CompressionStream.st
changeset 1082 3086d4d4f0b9
parent 1081 40e1129995f5
child 1083 5a0ae155f400
equal deleted inserted replaced
1081:40e1129995f5 1082:3086d4d4f0b9
    28     ^ self basicNew openWithMode:#writeonly on:aStream
    28     ^ self basicNew openWithMode:#writeonly on:aStream
    29 ! !
    29 ! !
    30 
    30 
    31 !CompressionStream class methodsFor:'test'!
    31 !CompressionStream class methodsFor:'test'!
    32 
    32 
    33 readTest
    33 doTestNextN
       
    34 "
       
    35     CompressionStream doTestNextN
       
    36 "
       
    37    |stream time file zipCont nxtCont|
       
    38 
       
    39    file := '/phys/exept/tmp/yyy/201--T22--D.20000415.SAGSA.DE0220523.gz' asFilename.
       
    40    file isReadable ifFalse:[^ self error:'not existant'].
       
    41 
       
    42    time := Time millisecondsToRun:[ |zipStream|
       
    43         zipStream := stream := zipCont := nil.
       
    44         [
       
    45             stream    := file readStream.
       
    46             zipStream := ZipStream readOpenOn:stream.
       
    47             zipCont   := zipStream contents.
       
    48         ] valueNowOrOnUnwindDo:[
       
    49             zipStream notNil ifTrue:[zipStream close].
       
    50             stream    notNil ifTrue:[stream close].
       
    51         ].
       
    52    ].
       
    53    Transcript showCR:('STX   Time : %1  Size: %2' bindWith:time with:(zipCont size)).
       
    54 
       
    55    time := Time millisecondsToRun:[ |zipStream wstream|
       
    56         zipStream := stream := nxtCont := nil.
       
    57         [
       
    58             stream    := file readStream.
       
    59             wstream   := '' writeStream.
       
    60             zipStream := ZipStream readOpenOn:stream.
       
    61 
       
    62             [zipStream atEnd] whileFalse:[
       
    63                 wstream nextPutAll:(zipStream next:117)
       
    64             ].
       
    65             nxtCont := wstream contents.
       
    66         ] valueNowOrOnUnwindDo:[
       
    67             zipStream notNil ifTrue:[zipStream close].
       
    68             stream    notNil ifTrue:[stream close].
       
    69         ].
       
    70    ].
       
    71    Transcript showCR:('NEXT  Time : %1  Size: %2' bindWith:time with:(nxtCont size)).
       
    72 
       
    73    nxtCont = zipCont ifTrue:[ Transcript showCR:'OK' ]
       
    74                     ifFalse:[ self error:'contents differs' ].
       
    75 !
       
    76 
       
    77 
       
    78 doTestSkipN
       
    79 "
       
    80     CompressionStream doTestSkipN
       
    81 "
       
    82    |stream time file skpCont nxtCont skip|
       
    83 
       
    84    file := '/phys/exept/tmp/yyy/201--T22--D.20000415.SAGSA.DE0220523.gz' asFilename.
       
    85    file isReadable ifFalse:[^ self error:'not existant'].
       
    86 
       
    87    skip := 6885379.
       
    88 
       
    89    time := Time millisecondsToRun:[ |zipStream wstream|
       
    90         zipStream := stream := nxtCont := nil.
       
    91         [
       
    92             stream    := file readStream.
       
    93             wstream   := '' writeStream.
       
    94             zipStream := ZipStream readOpenOn:stream.
       
    95             skip timesRepeat:[ zipStream next ].
       
    96 
       
    97             [zipStream atEnd] whileFalse:[
       
    98                 wstream nextPutAll:(zipStream next:117)
       
    99             ].
       
   100             nxtCont := wstream contents.
       
   101         ] valueNowOrOnUnwindDo:[
       
   102             zipStream notNil ifTrue:[zipStream close].
       
   103             stream    notNil ifTrue:[stream close].
       
   104         ].
       
   105    ].
       
   106 
       
   107    Transcript showCR:('STX   Time : %1  Size: %2' bindWith:time with:(nxtCont size)).
       
   108 
       
   109    time := Time millisecondsToRun:[ |zipStream wstream|
       
   110         zipStream := stream := skpCont := nil.
       
   111         [
       
   112             stream    := file readStream.
       
   113             wstream   := '' writeStream.
       
   114             zipStream := ZipStream readOpenOn:stream.
       
   115             zipStream skip:skip.
       
   116             [zipStream atEnd] whileFalse:[
       
   117                 wstream nextPutAll:(zipStream next:117)
       
   118             ].
       
   119             skpCont := wstream contents.
       
   120         ] valueNowOrOnUnwindDo:[
       
   121             zipStream notNil ifTrue:[zipStream close].
       
   122             stream    notNil ifTrue:[stream close].
       
   123         ].
       
   124    ].
       
   125    Transcript showCR:('NEXT  Time : %1  Size: %2' bindWith:time with:(skpCont size)).
       
   126 
       
   127    nxtCont = skpCont ifTrue:[ Transcript showCR:'OK' ]
       
   128                     ifFalse:[ self error:'contents differs' ].
       
   129 
       
   130 !
       
   131 
       
   132 doTestUnixAgainstClass
       
   133 "
       
   134     CompressionStream doTestUnixAgainstClass
       
   135 "
    34    |stream time file zipCont cmdCont|
   136    |stream time file zipCont cmdCont|
    35 
   137 
    36    file := '/phys/exept/tmp/yyy/201--T22--D.20000415.SAGSA.DE0220523.gz' asFilename.
   138    file := '/phys/exept/tmp/yyy/201--T22--D.20000415.SAGSA.DE0220523.gz' asFilename.
    37    file isReadable ifFalse:[^ self error:'not existant'].
   139    file isReadable ifFalse:[^ self error:'not existant'].
    38 
   140 
   470     position := position + 1.
   572     position := position + 1.
   471     byte := outputBytes at:position.
   573     byte := outputBytes at:position.
   472 
   574 
   473     binary ifTrue:[^ byte ].
   575     binary ifTrue:[^ byte ].
   474   ^ Character value:byte
   576   ^ Character value:byte
       
   577 !
       
   578 
       
   579 next:n
       
   580     "return the next count elements of the stream as a collection.
       
   581      Redefined to return a String or ByteArray and for optimization
       
   582     "
       
   583     |data count offset species|
       
   584 
       
   585     mode == #readonly ifFalse:[ self errorReadOnly ].
       
   586 
       
   587     species := self contentsSpecies.
       
   588 
       
   589     self canReadWithoutBlocking ifFalse:[
       
   590         ^ species new
       
   591     ].
       
   592     data := species new:n.
       
   593     offset := 1.
       
   594 
       
   595     [ self canReadWithoutBlocking ] whileTrue:[
       
   596         count  := self z_nextAvailableInto:data startingAt:offset.
       
   597         offset := count + offset.
       
   598         offset > n ifTrue:[^ data ]
       
   599     ].
       
   600     ^ data copyFrom:1 to:(offset - 1)
       
   601 !
       
   602 
       
   603 skip:count 
       
   604     "skip count objects, return the receiver
       
   605      redefined for optimization
       
   606     "
       
   607     |n avail|
       
   608 
       
   609     mode == #readonly ifFalse:[ self errorReadOnly ].
       
   610     n := count.
       
   611 
       
   612     [ self canReadWithoutBlocking ] whileTrue:[
       
   613         avail := readLimit - position.
       
   614 
       
   615         avail >= n ifTrue:[
       
   616             position := position + n.
       
   617           ^ self
       
   618         ].
       
   619         position := readLimit := 0. "/ reset input
       
   620         n := n - avail.
       
   621     ].
   475 ! !
   622 ! !
   476 
   623 
   477 !CompressionStream methodsFor:'startup & release'!
   624 !CompressionStream methodsFor:'startup & release'!
   478 
   625 
   479 close
   626 close