suppress header & checksum configurable
authorca
Mon, 03 Aug 2009 14:51:07 +0200
changeset 2194 38a073a3261b
parent 2193 db70507b21ba
child 2195 9864349ff9d3
suppress header & checksum configurable
CompressionStream.st
--- a/CompressionStream.st	Mon Aug 03 14:50:50 2009 +0200
+++ b/CompressionStream.st	Mon Aug 03 14:51:07 2009 +0200
@@ -13,7 +13,7 @@
 
 Stream subclass:#CompressionStream
 	instanceVariableNames:'onStream hitEOF binary position readLimit mode inputBytes
-		outputBytes zstream'
+		outputBytes zstream suppressHeaderAndChecksum'
 	classVariableNames:'BlockSize'
 	poolDictionaries:''
 	category:'System-Compress'
@@ -181,10 +181,10 @@
 
     count := aCollection size - offset + 1.
     count < 0 ifTrue:[
-        self zerror:'invalid arguments'
+	self zerror:'invalid arguments'
     ].
     count == 0 ifTrue:[
-        ^ 0
+	^ 0
     ].
 
     count := avail min:count.
@@ -193,7 +193,7 @@
     start := position.
     position := position + count.
 
-%{  
+%{
     unsigned char * _dstPt;
     int             _count = __intVal( count );
     int             _offset = __intVal( offset );
@@ -201,11 +201,11 @@
     OBJ             _srcObj = __INST( outputBytes );
 
     if( __isBytes(aCollection) ) {
-        _dstPt = (unsigned char *) (__byteArrayVal(aCollection));
+	_dstPt = (unsigned char *) (__byteArrayVal(aCollection));
     } else if (__isString(aCollection)) {
-        _dstPt = (unsigned char *) (__stringVal( aCollection));
+	_dstPt = (unsigned char *) (__stringVal( aCollection));
     } else {
-        goto error;
+	goto error;
     }
 
     _dstPt  = _dstPt + _offset - 1;
@@ -321,25 +321,25 @@
     |n|
 
     mode == #readonly ifFalse:[
-        self errorWriteOnly
+	self errorWriteOnly
     ].
     hitEOF == true ifTrue:[^ false].
 
     position >= readLimit ifTrue:[
-        [(readLimit := self zinflate) == 0] whileTrue:[
-            n := onStream nextBytes:(inputBytes size) into:inputBytes startingAt:1.
+	[(readLimit := self zinflate) == 0] whileTrue:[
+	    n := onStream nextBytes:(inputBytes size) into:inputBytes startingAt:1.
 
-            n == 0 ifTrue:[
-                hitEOF := true.
-                ^ false
-            ].
-            self zset_avail_in:n.
-        ].
-        readLimit isNil ifTrue:[
-            hitEOF := true.
-            ^ false
-        ].
-        position := 0.
+	    n == 0 ifTrue:[
+		hitEOF := true.
+		^ false
+	    ].
+	    self zset_avail_in:n.
+	].
+	readLimit isNil ifTrue:[
+	    hitEOF := true.
+	    ^ false
+	].
+	position := 0.
     ].
     ^ true
 !
@@ -363,6 +363,13 @@
     ^ mode == #readonly
 !
 
+isHeaderAndChecksumSuppressed
+    "answer true if the checksum and header are suppressed;
+    the default is true (backward compatibility)"
+
+    ^ suppressHeaderAndChecksum ? true
+!
+
 isWritable
     "return true, if this stream can be written to"
 
@@ -446,16 +453,16 @@
     |count remaining offset|
 
     self canReadWithoutBlocking ifFalse:[
-        ^ 0
+	^ 0
     ].
     offset := startIndex.
     remaining := n.
 
     [self canReadWithoutBlocking] whileTrue:[
-        count  := self z_nextAvailableInto:aBuffer startingAt:offset maxCount:remaining.
-        offset := count + offset.
-        remaining := remaining - count.
-        remaining == 0 ifTrue:[^ n]
+	count  := self z_nextAvailableInto:aBuffer startingAt:offset maxCount:remaining.
+	offset := count + offset.
+	remaining := remaining - count.
+	remaining == 0 ifTrue:[^ n]
     ].
     ^ n - remaining
 !
@@ -590,7 +597,7 @@
 !CompressionStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/CompressionStream.st,v 1.25 2009-07-31 12:15:06 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/CompressionStream.st,v 1.26 2009-08-03 12:51:07 ca Exp $'
 ! !
 
 CompressionStream initialize!