Hello,
base64-encoded streams don't respond to #atEnd properly. Example #1: | stream output string | string := '/w=='. stream := (string asByteArray withEncoding: #base64) readStream. output := ( ByteArray new: string size ) writeStream. [ stream atEnd ] whileFalse: [ output nextPut: stream next ]. output contents. fails with "Improper store into indexable object" Example #2: even worse: when using '////' as input, no error will be raised, but the output is too short (only 1 byte instead of three bytes). Example #3: same input as #1, without using #atEnd, properly decoded: | stream output string | string := '/w=='. stream := (string asByteArray withEncoding: #base64) readStream. output := ( ByteArray new: string size ) writeStream. [ (byte := stream next) notNil ] whileTrue: [ output nextPut: byte ]. output contents. _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Hi,
This is one of the reasons I wrote a Base64 read and write stream for the PostgreSQL drivers. Also, I wanted a Base64 encoder/decoder which was portable. Does this work for you (when you have the PostgreSQL library loaded): | stream output string | string := '/w=='. stream := Base64EncodingReadStream on: string. output := ( ByteArray new: string size ) writeStream. [ stream atEnd ] whileFalse: [ output nextPut: stream next ]. output contents ? All the best, Bruce 2009/11/17 Holger Kleinsorgen <[hidden email]>: > Hello, > > base64-encoded streams don't respond to #atEnd properly. > > Example #1: > > | stream output string | > string := '/w=='. > stream := (string asByteArray withEncoding: #base64) readStream. > output := ( ByteArray new: string size ) writeStream. > [ stream atEnd ] whileFalse: [ output nextPut: stream next ]. > output contents. > > fails with "Improper store into indexable object" > > > Example #2: > > even worse: when using '////' as input, no error will be raised, but the > output is too short (only 1 byte instead of three bytes). > > > Example #3: > > same input as #1, without using #atEnd, properly decoded: > > | stream output string | > string := '/w=='. > stream := (string asByteArray withEncoding: #base64) readStream. > output := ( ByteArray new: string size ) writeStream. > [ (byte := stream next) notNil ] whileTrue: [ output nextPut: byte ]. > output contents. > _______________________________________________ > vwnc mailing list > [hidden email] > http://lists.cs.uiuc.edu/mailman/listinfo/vwnc > -- Make the most of your skills - with OpenSkills http://www.openskills.org/ _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Bruce Badger schrieb:
> Hi, > > This is one of the reasons I wrote a Base64 read and write stream for > the PostgreSQL drivers. Also, I wanted a Base64 encoder/decoder which > was portable. > > Does this work for you (when you have the PostgreSQL library loaded): > > | stream output string | > string := '/w=='. > stream := Base64EncodingReadStream on: string. > output := ( ByteArray new: string size ) writeStream. > [ stream atEnd ] whileFalse: [ output nextPut: stream next ]. > output contents > yes, Base64EncodingReadStream works as expected (testet with both input strings). the problem seems to be that EncodedStream simply delegates #atEnd to the underlying stream, therefore bypassing lookahead data that the encoder might have stored. _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Free forum by Nabble | Edit this page |