[squeak-dev] Re: Streaming directly from WebResponse content to SketchMorph

Andreas.Raab andreas.raab at gmx.de
Thu Oct 18 08:57:47 UTC 2012


Casimiro de Almeida Barreto wrote
> On 17-10-2012 20:42, Bert Freudenberg wrote:
>> (PNGReadWriter formFromStream: (HTTPClient httpGet:
>> 'http://squeak.org/img/squeaklogosmallerpng')) asMorph openInHand
> Not so easy... site requires authentication (hence the idea of using
> WebClient...)
> 
> | wc url resp ucode passw sm |
> 
> Transcript clear.
> 
> url := 'http://127.0.0.1:8088/(... lots of path elements ...)/image.png'.
> 
> ucode := 'xxx'.
> passw := 'yyy'.
> 
>    
> resp := (WebClient) new
>                 acceptCookies: true;
>                 username: ucode;
>                 password: passw;
>                 httpGet: url.
>            
> resp contentStream binary.
> 
> (PNGReadWriter formFromStream: resp contentStream) asMorph openInHand
> 
> It fails with "Image format not recognized.
> 
> What happens is that in the test there's something like:
> 
> understandsImageFormat
>    
>     #(137 80 78 71 13 10 26 10) do: [ :byte |
>         stream next = byte ifFalse: [^ false]].
>     ^ true
> 
> and while byte is Character stream returns SmallInteger. So, yeah, first
> element of list is 137 and first byte of stream is 137 but comparsion
> fails. If forced (byte asInteger) it will fail later on decoding.
> 
> Interesting enough is that when it reads from a file stream it works
> (provided content binary).

Yes, but the reason is different. The ImageReadWriters assume seekable
streams, and PNGReadWriter itself tries to do a "stream reset" which fails
on SocketStream. That's why it refuses to read the data directly from the
(socket) stream. Which means the following should work fine:

url := 'http://www.fnordware.com/superpng/pnggrad8rgb.png'.   
resp := (WebClient) new httpGet: url.
resp isSuccess ifFalse:[self error: resp content].
stream := RWBinaryOrTextStream with: resp content.
(PNGReadWriter formFromStream: stream) asMorph openInHand

Cheers,
  - Andreas




--
View this message in context: http://forum.world.st/Streaming-directly-from-WebResponse-content-to-SketchMorph-tp4651737p4651772.html
Sent from the Squeak - Dev mailing list archive at Nabble.com.


More information about the Squeak-dev mailing list