base64 decoding

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

base64 decoding

Sylvain pralon
hello
 
I work with sockets and one of them returned me a base64 encoded stream.
I have some problems to decode it.
Please help me
 
thanks
 
sylvain Pralon
 
Reply | Threaded
Open this post in threaded view
|

RE: base64 decoding

Paul Baumann
Others will know what support VW has for base64 encoding.
 
If VW doesn't have anything then you can use the base64 stream wrapper that comes in SRP http://www.sourceforge.net/projects/srp. As the name implies, it simply wraps another stream. One of the cool things about the implementation is that it allows repositioning and re-write of base64 encoded data. Not a feature you'll need for just wrapping and reading to meet your needs, but cool nonetheless.
 
Paul Baumann 
 


From: Sylvain Pralon [mailto:[hidden email]]
Sent: Monday, April 23, 2007 8:51 AM
To: [hidden email]
Subject: base64 decoding

hello
 
I work with sockets and one of them returned me a base64 encoded stream.
I have some problems to decode it.
Please help me
 
thanks
 
sylvain Pralon
 

 

 

 


This message may contain confidential information and is intended for specific recipients unless explicitly noted otherwise. If you have reason to believe you are not an intended recipient of this message, please delete it and notify the sender. This message may not represent the opinion of IntercontinentalExchange, Inc. (ICE), its subsidiaries or affiliates, and does not constitute a contract or guarantee. Unencrypted electronic mail is not secure and the recipient of this message is expected to provide safeguards from viruses and pursue alternate means of communication where privacy or a binding message is desired.

Reply | Threaded
Open this post in threaded view
|

Re: base64 decoding

kobetic
In reply to this post by Sylvain pralon
There's the #base64 encoding provided with the VW Net Clients, currently in the Protocols-Common package. It's a bit messy to use though, because base64 encoding just doesn't fit very well into the EncodedStream setup. Consequently I'd probably recommend first looking at the Base64 streams that are part of the Postgres-EXDI support. However if you'd rather use something supported by Cincom, in the upcoming VW7.5 we are releasing a new class of DecodedStreams, where base64 encoding fits  better and should be straightforward to use. Here are some examples:

Example - Writing

        | stream input |
        input := ByteArray withAll: (1 to: 32).
        stream := DecodedStream
                                on: String new writeStream
                                encodedBy: B64StreamDecoder asEncoder.
        stream nextPutAll: input.
        stream close.
        stream encodedContents.


Example - Reading

        | stream input |
        input := 'AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyA='.
        stream := DecodedStream
                                on: input readStream
                                encodedBy: B64StreamDecoder asEncoder.
        stream contents.

If you load a recent version of Protocols-Common from the public repository, you can have it right away.

HTH,

Martin

Sylvain Pralon wrote:

> hello
>  
> I work with sockets and one of them returned me a base64 encoded stream.
> I have some problems to decode it.
> Please help me
>  
> thanks
>  
> sylvain Pralon
>  

Reply | Threaded
Open this post in threaded view
|

Re: base64 decoding

Bruce Badger
In reply to this post by Sylvain pralon
On 23/04/07, Sylvain Pralon <[hidden email]> wrote:
> hello
>
> I work with sockets and one of them returned me a base64 encoded stream.
> I have some problems to decode it.
> Please help me

You can find a portable implementation of Base64 encoding and decoding
streams shipped with the PostgreSQL library.  If you are using a
VisualWorks non-commercial image you'll find it's already loaded.

Browse for references to Base64EncodingReadStream and
Base64EncodingWriteStream for examples of how to read and write Base64
encoded data or even better, load up the Base64Encoding-Tests package
from the public Store and look at the test cases.  But in your case as
you say you have a stream containing Base64 encoded data this should
work:

decodedBytes := (Base64EncodingReadStream onStream: encodedStream) upToEnd.

All the best,
    Bruce
--
Make the most of your skills - with OpenSkills
http://www.openskills.org/

Reply | Threaded
Open this post in threaded view
|

Re: base64 decoding

Reinout Heeck
In reply to this post by kobetic

On Apr 23, 2007, at 5:43 PM, Martin Kobetic wrote:

> stream := DecodedStream on: String new writeStream
> encodedBy: B64StreamDecoder asEncoder.


If I may:

What the heck is a B64Stream?
Smalltalk idiom used to be to write that as Base64Stream - what  
happened?


Furthermore we have a class 'Decoder' that is sent #asEncoder.
I would prefer to call such a class an Encoder-Decoder - in our  
vernacular that would be 'Codec'.

        stream := DecodedStream
                        on: String new writeStream
                        encodedBy: Base64Codec asEncoder.





Sorry - can't stand sore eyes ;-)

R
-

Reply | Threaded
Open this post in threaded view
|

Re: base64 decoding

kobetic
Reinout Heeck wrote:

>
> On Apr 23, 2007, at 5:43 PM, Martin Kobetic wrote:
>
>>     stream := DecodedStream                 on: String new
>> writeStream                 encodedBy: B64StreamDecoder asEncoder.
>
>
> If I may:
>
> What the heck is a B64Stream?
> Smalltalk idiom used to be to write that as Base64Stream - what happened?

Well, this is somewhat subjective. I personally don't see B64 as such a big deal. On the other hand I can easily imagine someone arguing that only BaseSixtyFourEncoderForDecodedStream is properly intention revealing and the only "true smalltalk way" to name this class. And I'd be ready to strangle him with bare hands every time I saw it :-). Anyway, in reality the name simply evolved to its current form. It started out as a new version of encoder for EncodedStream, and since Base64EncodedStream (including the #base64 symbol) was already taken, I called it B64 at that point. Then DecodedStream came and was clearly a better fit so the encoder got converted for that and it seemed important to emphasize that it is for DecodeStream now, thus the final B64StreamDecoder. I don't have a problem with Base64StreamDecoder or Codec or whatever (as long as there's some level of consistency across the API). In this particular case I could agree that Base64 is better than B64, but I don't t
hink it's such a qualitative jump either. Quick google search confirms that I'm far from being the first one referring to the encoding that way so it definitely shouldn't cause too much confusion.

> Furthermore we have a class 'Decoder' that is sent #asEncoder.
> I would prefer to call such a class an Encoder-Decoder - in our
> vernacular that would be 'Codec'.
>
>     stream := DecodedStream
>             on: String new writeStream
>             encodedBy: Base64Codec asEncoder.

Yes, Decoder asEncoder inside DecodedStream is confusing at best. That's pretty clear at the first sight of the example. There are many possible ways to clean this up and even more loose ends that should be tied up as well.  We're getting there, incrementally. In the mean time using #new instead of #asEncoder should get you through without bodily harm I hope :-).

Cheers,

Martin