[squeak-dev] Streaming directly from WebResponse content to
arning315 at comcast.net
Thu Oct 18 02:06:45 UTC 2012
The problem with this approach is that the contentStream is a
SocketStream which has some issues:
- does not undersatnd #reset. This is used after matching the first
bytes to ensure starting at the beginning when building the image.
- has wobbly #atEnd. The png reader keeps getting data until the end of
the stream, but the SocketStream won't answer true to #atEnd until the
socket is closed.
The following will work, but I'm not certain if WebClient might give you
the response before all needed data has arrived, in which case it will
not work. ;-)
| url resp ucode passw myData myStream |
url := 'http://127.0.0.1/~bob/images/addInitialAction_button.png'.
ucode := 'xxx'.
passw := 'yyy'.
resp := (WebClient) new
resp contentStream binary.
myData _ resp contentStream nextAllInBuffer.
myStream _ ReadStream on: myData.
(PNGReadWriter on: myStream) nextImage asMorph openInHand
On 10/17/12 8:38 PM, 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
> | 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:
> #(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).
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Squeak-dev