ZipStream.st
changeset 2190 6c3f9241753a
parent 2178 f6f0d919aed2
child 2193 db70507b21ba
--- a/ZipStream.st	Mon Jul 27 18:04:15 2009 +0200
+++ b/ZipStream.st	Fri Jul 31 13:16:42 2009 +0200
@@ -85,7 +85,7 @@
 
 examples
 "
-                                                                [exBegin]
+								[exBegin]
     |compressedDataStream zipStream compressedData uncompressedData|
 
     compressedDataStream := #[] writeStream.
@@ -98,18 +98,18 @@
     zipStream := ZipStream readOpenOn:(compressedData readStream).
 
     zipStream notNil ifTrue:[
-        |stream c|
+	|stream c|
 
-        stream := '' writeStream.
+	stream := '' writeStream.
 
-        [ (c := zipStream next) notNil ] whileTrue:[
-            stream nextPut:c
-        ].
-        stream close.
-        uncompressedData := stream contents.
+	[ (c := zipStream next) notNil ] whileTrue:[
+	    stream nextPut:c
+	].
+	stream close.
+	uncompressedData := stream contents.
     ].
     ^ uncompressedData
-                                                                [exEnd]
+								[exEnd]
 
 
 "
@@ -142,13 +142,13 @@
 !ZipStream class methodsFor:'instance creation'!
 
 readOpenAsZipStreamOn:aStream
-    "open to read data compressed from stream, 
+    "open to read data compressed from stream,
      the default readOpenOn: will open ZipStream as gzip stream"
     ^ self basicNew streamOpenWithMode:#readonly on:aStream
 !
 
 writeOpenAsZipStreamOn:aStream
-    "open to write data compressed to stream, 
+    "open to write data compressed to stream,
      the default writeOpenOn: will open ZipStream as gzip stream"
     ^ self basicNew streamOpenWithMode:#writeonly on:aStream
 ! !
@@ -250,20 +250,20 @@
      and return the updated crc "
 %{
     if( (__isInteger(crc)))     {
-        char __byte;
-        uLong  __crc;
+	char __byte;
+	uLong  __crc;
 
-        if (__isCharacter(aCharacterOrByte)) {
-            __byte = __smallIntegerVal(__characterVal(aCharacterOrByte));
-        } else if (__isSmallInteger(aCharacterOrByte)) {
-            __byte = __intVal(aCharacterOrByte);
-        } else{
-            goto err;
-        }
+	if (__isCharacter(aCharacterOrByte)) {
+	    __byte = __smallIntegerVal(__characterVal(aCharacterOrByte));
+	} else if (__isSmallInteger(aCharacterOrByte)) {
+	    __byte = __intVal(aCharacterOrByte);
+	} else{
+	    goto err;
+	}
 
-        __crc  = __unsignedLongIntVal( crc );
-        __crc = crc32(__crc, (Byte *) &__byte, 1 );
-        RETURN( __MKUINT(__crc) );
+	__crc  = __unsignedLongIntVal( crc );
+	__crc = crc32(__crc, (Byte *) &__byte, 1 );
+	RETURN( __MKUINT(__crc) );
     }
 err:;
 %}.
@@ -312,32 +312,32 @@
 
 %{
     if (__isInteger(crc) && __isSmallInteger(start) && __isSmallInteger(stop)) {
-        char * __bytes  = 0;
-        unsigned int __size;
-        uLong  __crc  = __unsignedLongIntVal( crc );
-        uInt   __start = __intVal( start );
-        uInt   __stop = __intVal( stop );
+	char * __bytes  = 0;
+	unsigned int __size;
+	uLong  __crc  = __unsignedLongIntVal( crc );
+	uInt   __start = __intVal( start );
+	uInt   __stop = __intVal( stop );
 
-        if (__isBytes(bytesIn)) {
-            __bytes = __byteArrayVal(bytesIn);
-            __size = __byteArraySize(bytesIn);
-        } else if (__isString(bytesIn)) {
-            __bytes = __stringVal(bytesIn);
-            __size = __stringSize(bytesIn);
-        } else {
-            goto err;
-        }
+	if (__isBytes(bytesIn)) {
+	    __bytes = __byteArrayVal(bytesIn);
+	    __size = __byteArraySize(bytesIn);
+	} else if (__isString(bytesIn)) {
+	    __bytes = __stringVal(bytesIn);
+	    __size = __stringSize(bytesIn);
+	} else {
+	    goto err;
+	}
 
 
-        if (__start < 1 || __start > __size) goto err;
-        if (__stop < 1 || __stop > __size) goto err;
+	if (__start < 1 || __start > __size) goto err;
+	if (__stop < 1 || __stop > __size) goto err;
 
-        __size = __stop - __start + 1;
+	__size = __stop - __start + 1;
 
-        __bytes += __start - 1;
-        __crc = crc32(__crc, (Byte *) __bytes, __size );
+	__bytes += __start - 1;
+	__crc = crc32(__crc, (Byte *) __bytes, __size );
 
-        RETURN( __MKUINT(__crc) );
+	RETURN( __MKUINT(__crc) );
     }
 err:;
 %}.
@@ -460,7 +460,7 @@
 	_errorNo = deflateInit2( & _zstream->stream
 			       , __intVal( level )
 			       , Z_DEFLATED
-			       , -MAX_WBITS
+			       , MAX_WBITS
 			       , DEF_MEM_LEVEL
 			       , Z_DEFAULT_STRATEGY
 			       );
@@ -612,7 +612,7 @@
 	zstream_s * _zstream = (zstream_s *) __externalBytesAddress( _zstreamObj );
 
 	_zstream->op_mode = e_opmode_inflate;
-	_errorNo = inflateInit2( & _zstream->stream, -MAX_WBITS );
+	_errorNo = inflateInit2( & _zstream->stream, MAX_WBITS );
 
 	if( _errorNo == Z_OK )
 	    RETURN( self );
@@ -705,11 +705,11 @@
     super openWithMode:aMode on:aStream.
 
     self isReadable ifTrue:[
-        "Check for the gzip magic id"
-        self readHeader
+	"Check for the gzip magic id"
+	self readHeader
     ] ifFalse:[
-        "write the gzip magic id"
-        self writeHeader
+	"write the gzip magic id"
+	self writeHeader
     ].
 !
 
@@ -718,35 +718,35 @@
     |flags|
 
     GZ_MAGIC_ID do:[:b|
-        onStream nextByte ~~ b ifTrue:[ self zerror:'version error' ]
+	onStream nextByte ~~ b ifTrue:[ self zerror:'version error' ]
     ].
 
     onStream nextByte ~~ Z_DEFLATED ifTrue:[
-        self zerror:'invalid method (not deflated)'
+	self zerror:'invalid method (not deflated)'
     ].
 
     flags := onStream nextByte.
     (flags bitAnd:HEAD_RESERVED) ~~ 0 ifTrue:[
-        self zerror:'wrong data format'
+	self zerror:'wrong data format'
     ].
 
     "discard time, xflags and OS code"
     onStream skip:6.
 
     (flags bitAnd:HEAD_EXTRA_FIELD) ~~ 0 ifTrue:[|len|
-        "skip the extra field"
-        len := onStream nextByte + (onStream nextByte bitShift:8).
-        len timesRepeat:[ onStream nextByte ].
+	"skip the extra field"
+	len := onStream nextByte + (onStream nextByte bitShift:8).
+	len timesRepeat:[ onStream nextByte ].
     ].
 
     (flags bitAnd:HEAD_ORIG_NAME) ~~ 0 ifTrue:[|b|
-        "skip the original file name"
-        [ (b := onStream nextByte) ~~ 0 ] whileTrue.
+	"skip the original file name"
+	[ (b := onStream nextByte) ~~ 0 ] whileTrue.
     ].
 
     (flags bitAnd:HEAD_CRC) ~~ 0 ifTrue:[
-        "skip the header crc"
-        onStream skip:2.
+	"skip the header crc"
+	onStream skip:2.
     ].
 !
 
@@ -774,7 +774,7 @@
 !ZipStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/ZipStream.st,v 1.33 2009-06-30 19:05:10 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/ZipStream.st,v 1.34 2009-07-31 11:16:42 cg Exp $'
 ! !
 
 ZipStream initialize!