--- a/CompressionStream.st Thu Aug 22 09:51:15 2002 +0200
+++ b/CompressionStream.st Thu Aug 22 10:29:44 2002 +0200
@@ -30,7 +30,109 @@
!CompressionStream class methodsFor:'test'!
-readTest
+doTestNextN
+"
+ CompressionStream doTestNextN
+"
+ |stream time file zipCont nxtCont|
+
+ file := '/phys/exept/tmp/yyy/201--T22--D.20000415.SAGSA.DE0220523.gz' asFilename.
+ file isReadable ifFalse:[^ self error:'not existant'].
+
+ time := Time millisecondsToRun:[ |zipStream|
+ zipStream := stream := zipCont := nil.
+ [
+ stream := file readStream.
+ zipStream := ZipStream readOpenOn:stream.
+ zipCont := zipStream contents.
+ ] valueNowOrOnUnwindDo:[
+ zipStream notNil ifTrue:[zipStream close].
+ stream notNil ifTrue:[stream close].
+ ].
+ ].
+ Transcript showCR:('STX Time : %1 Size: %2' bindWith:time with:(zipCont size)).
+
+ time := Time millisecondsToRun:[ |zipStream wstream|
+ zipStream := stream := nxtCont := nil.
+ [
+ stream := file readStream.
+ wstream := '' writeStream.
+ zipStream := ZipStream readOpenOn:stream.
+
+ [zipStream atEnd] whileFalse:[
+ wstream nextPutAll:(zipStream next:117)
+ ].
+ nxtCont := wstream contents.
+ ] valueNowOrOnUnwindDo:[
+ zipStream notNil ifTrue:[zipStream close].
+ stream notNil ifTrue:[stream close].
+ ].
+ ].
+ Transcript showCR:('NEXT Time : %1 Size: %2' bindWith:time with:(nxtCont size)).
+
+ nxtCont = zipCont ifTrue:[ Transcript showCR:'OK' ]
+ ifFalse:[ self error:'contents differs' ].
+!
+
+
+doTestSkipN
+"
+ CompressionStream doTestSkipN
+"
+ |stream time file skpCont nxtCont skip|
+
+ file := '/phys/exept/tmp/yyy/201--T22--D.20000415.SAGSA.DE0220523.gz' asFilename.
+ file isReadable ifFalse:[^ self error:'not existant'].
+
+ skip := 6885379.
+
+ time := Time millisecondsToRun:[ |zipStream wstream|
+ zipStream := stream := nxtCont := nil.
+ [
+ stream := file readStream.
+ wstream := '' writeStream.
+ zipStream := ZipStream readOpenOn:stream.
+ skip timesRepeat:[ zipStream next ].
+
+ [zipStream atEnd] whileFalse:[
+ wstream nextPutAll:(zipStream next:117)
+ ].
+ nxtCont := wstream contents.
+ ] valueNowOrOnUnwindDo:[
+ zipStream notNil ifTrue:[zipStream close].
+ stream notNil ifTrue:[stream close].
+ ].
+ ].
+
+ Transcript showCR:('STX Time : %1 Size: %2' bindWith:time with:(nxtCont size)).
+
+ time := Time millisecondsToRun:[ |zipStream wstream|
+ zipStream := stream := skpCont := nil.
+ [
+ stream := file readStream.
+ wstream := '' writeStream.
+ zipStream := ZipStream readOpenOn:stream.
+ zipStream skip:skip.
+ [zipStream atEnd] whileFalse:[
+ wstream nextPutAll:(zipStream next:117)
+ ].
+ skpCont := wstream contents.
+ ] valueNowOrOnUnwindDo:[
+ zipStream notNil ifTrue:[zipStream close].
+ stream notNil ifTrue:[stream close].
+ ].
+ ].
+ Transcript showCR:('NEXT Time : %1 Size: %2' bindWith:time with:(skpCont size)).
+
+ nxtCont = skpCont ifTrue:[ Transcript showCR:'OK' ]
+ ifFalse:[ self error:'contents differs' ].
+
+!
+
+doTestUnixAgainstClass
+"
+ CompressionStream doTestUnixAgainstClass
+"
|stream time file zipCont cmdCont|
file := '/phys/exept/tmp/yyy/201--T22--D.20000415.SAGSA.DE0220523.gz' asFilename.
@@ -472,6 +574,51 @@
binary ifTrue:[^ byte ].
^ Character value:byte
+!
+
+next:n
+ "return the next count elements of the stream as a collection.
+ Redefined to return a String or ByteArray and for optimization
+ "
+ |data count offset species|
+
+ mode == #readonly ifFalse:[ self errorReadOnly ].
+
+ species := self contentsSpecies.
+
+ self canReadWithoutBlocking ifFalse:[
+ ^ species new
+ ].
+ data := species new:n.
+ offset := 1.
+
+ [ self canReadWithoutBlocking ] whileTrue:[
+ count := self z_nextAvailableInto:data startingAt:offset.
+ offset := count + offset.
+ offset > n ifTrue:[^ data ]
+ ].
+ ^ data copyFrom:1 to:(offset - 1)
+!
+
+skip:count
+ "skip count objects, return the receiver
+ redefined for optimization
+ "
+ |n avail|
+
+ mode == #readonly ifFalse:[ self errorReadOnly ].
+ n := count.
+
+ [ self canReadWithoutBlocking ] whileTrue:[
+ avail := readLimit - position.
+
+ avail >= n ifTrue:[
+ position := position + n.
+ ^ self
+ ].
+ position := readLimit := 0. "/ reset input
+ n := n - avail.
+ ].
! !
!CompressionStream methodsFor:'startup & release'!