On Tue, May 17, 2011 at 10:31 PM, Sven Van Caekenberghe <sven@beta9.be>wrote:
On 17 May 2011, at 21:57, Mariano Martinez Peck wrote:
Sven, I want to make it work :)
so....the missing methods I told you that I need are:
#nextStringPut: #nextNumber:put: #nextInt32Put: #nextWordPut:
I guess these are pretty easy. But I think they clutter the interface of ZnBufferedWriteStream, so maybe you should make a subclass.
Yeah, don't worry. I can even duplicate the class hehehe
#contents
Implement #contents I guess it is something like:
ZnBufferedWriteStream >> contents ^ stream contents
Why to you need #contents ?
becasue I am an idiot. No, I don't need it. You are correct. Thanks for asking.
I would say that it goes a bit against the concept of a stream as a sink of data. I haven't looked, but I would guess that saying #contents to a FileStream is not efficient.
Those missing methods I need are implemented PositionableStream. I took the implementation from there and put it in ZnBufferedWriteStream. I just added to them a first line " self flushBufferIfFull."
That is probably OK, except when your string becomes larger than the buffer. Have a look at #nextPutAll:
I am not sure if I understood. The following are correct for sure then: #nextNumber:put: #nextInt32Put: #nextWordPut: And #nextStringPut: is like this: nextStringPut: s "Append the string, s, to the receiver. Only used by DataStream. Max size of 64*256*256*256." | length | self flushBufferIfFull. (length := s size) < 192 ifTrue: [self nextPut: length] ifFalse: [self nextPut: (length digitAt: 4)+192. self nextPut: (length digitAt: 3). self nextPut: (length digitAt: 2). self nextPut: (length digitAt: 1)]. self nextPutAll: s asByteArray. ^s which will finally send #nextPutAll: that does correct check.
The way I am creating it is like this:
stream := ZnBufferedWriteStream on: ((FileDirectory default forceNewFileNamed: 'mariano') binary).
So...is this correct Sven? My tests are green :)
That seems OK
Ok.
Still need to try benchmarks.
You might also consider playing with making the buffer larger.
yeah, I was trying that. Just by curious, why you put a 2^X number there? Ahh and for reading we don't need something special because it is already buffered? (I have been told that) Thanks a lot Sven, -- Mariano http://marianopeck.wordpress.com