Binary Read Streams from base64 decoded (ReadStream >> #binary ??)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Binary Read Streams from base64 decoded (ReadStream >> #binary ??)

darth-cheney
Hi all,

I have some code I'm trying to make cross platform. In one of my classes, I store bits describing a Form as a base64 encoded string. Pharo has dramatically changed their streams in recent years, so on that end this simply works:

`PNGReadWriter formFromStream: (self formSource base64Decoded readStream)`

In Squeak the readStream produced will be a textual stream, which is somewhat understandable. But when I look at ReadStream >> #binary , I see that the method is empty. Is this on purpose? The only other recourse I can find is to send the message #asBinaryOrTextStream, but this breaks compatibility with Pharo, so I was hoping for a more straightforward solution.

Any ideas?

--
Eric


Reply | Threaded
Open this post in threaded view
|

Re: Binary Read Streams from base64 decoded (ReadStream >> #binary ??)

Jakob Reschke
Hi Eric,

If you don't want to use RWBinaryOrTextStream or asBinaryOrTextStream,
you could try: aString base64Decoded asByteArray readStream.

Traditionally, Smalltalk file streams are either in text (ascii) or
binary mode, returning either bytes or characters when you read from
the stream. #binary is the selector to put a file stream in binary
mode. It has no effect on ReadStream, which is just a stream adapter
on a Collection, not a file stream. The ReadStream will always return
the elements of the collection, no conversion going on. ReadStream
implements binary just so you can put one into a method that expects a
file stream.

Kind regards,
Jakob

Am So., 22. Nov. 2020 um 16:12 Uhr schrieb Eric Gade <[hidden email]>:

>
> Hi all,
>
> I have some code I'm trying to make cross platform. In one of my classes, I store bits describing a Form as a base64 encoded string. Pharo has dramatically changed their streams in recent years, so on that end this simply works:
>
> `PNGReadWriter formFromStream: (self formSource base64Decoded readStream)`
>
> In Squeak the readStream produced will be a textual stream, which is somewhat understandable. But when I look at ReadStream >> #binary , I see that the method is empty. Is this on purpose? The only other recourse I can find is to send the message #asBinaryOrTextStream, but this breaks compatibility with Pharo, so I was hoping for a more straightforward solution.
>
> Any ideas?
>
> --
> Eric
>

Reply | Threaded
Open this post in threaded view
|

Re: Binary Read Streams from base64 decoded (ReadStream >> #binary ??)

darth-cheney


On Sun, Nov 22, 2020 at 10:47 AM Jakob Reschke <[hidden email]> wrote:
Hi Eric,

If you don't want to use RWBinaryOrTextStream or asBinaryOrTextStream,
you could try: aString base64Decoded asByteArray readStream.

Oh my, so obvious! Thanks

--
Eric