In all case, all should happen thru delegation and the facade should be rather dumb.5) For read, it might be a bit more involved if some buffer were used in intermediate wrappers, because they should push back the excess bytes read and restore the state of lower level binary stream...Here would be the Xtream way IMHO:4) For write, the facade should just ensure that buffers (if any) are properly flushed, and then just delegate to specialized wrapped streams.
1) At the end, the file should be handled as binary.
2) A facade BivalentReadStream (and BivalentWriteStream) would be created, able to switch encoding
3) The implementation would be to wrap either directly over the binary stream, or indirectly over an encoded stream which wraps other the binary stream.
2013/12/4 Sven Van Caekenberghe <sven@stfx.eu>To be somewhat compatible with existing streams, your memory stream should have the concept of �i am binary or textual� and be able to switch in-place between these two states (#binary, #ascii). Depending on its state it should then return bytes or characters (or collections thereof). Have a look at ZnLimitedReadStream>>#next and/or ZnBivalentWriteStream>>#nextPut:
On 04 Dec 2013, at 13:14, Max Leske <maxleske@gmail.com> wrote:
> Let me see what I can come up with.
To be 100% correct, encoding should be selectable. But maybe a default to utf-8 would be enough. You could have a look at ZnCharacter[Read|Write]Stream for inspiration.
My 2c.
> On 03.12.2013, at 19:36, Damien Cassou <damien.cassou@gmail.com> wrote:
>
>> Thanks Max for the report. Do you have an idea on how we could solve the problem ? The previous behaviour was not acceptable either because the streams that came out of a memory filesystem were the only ones with binary content
>>
>> On Dec 3, 2013 5:35 PM, "Max Leske" <maxleske@gmail.com> wrote:
>> Damien, Marcus
>>
>> this change breaks a lot of things in FileSystem-Git. I don�t disagree with the idea that reading characters should be default (one could argue about it�) but your change makes it IMPOSSIBLE to read bytes because unprintable characters are discarded! So if my ByteArray is a NULL terminated string, for instance, I can not check for the NULL termination anymore.
>>
>> Cheers,
>> Max
>