add instance creation methods to allow to open the ZipStream as
zip stream and not as gzip stream which is the default
--- a/ZipStream.st Thu Jun 05 11:15:06 2008 +0200
+++ b/ZipStream.st Thu Jun 05 11:16:16 2008 +0200
@@ -139,6 +139,20 @@
! !
+!ZipStream class methodsFor:'instance creation'!
+
+readOpenAsZipStreamOn:aStream
+ "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,
+ the default writeOpenOn: will open ZipStream as gzip stream"
+ ^ self basicNew streamOpenWithMode:#writeonly on:aStream
+! !
+
!ZipStream class methodsFor:'ZipInterface compatibility - compress/uncompress'!
compress: aUncompressedByteArray into: aCompressedByteArray
@@ -664,69 +678,69 @@
!ZipStream methodsFor:'startup & release'!
openWithMode:aMode on:aStream
-
+ "open stream and write or check gzip header"
super openWithMode:aMode on:aStream.
self isReadable ifTrue:[
- "Check for the gzip magic id"
- |flags|
+ "Check for the gzip magic id"
+ |flags|
- GZ_MAGIC_ID do:[:b|
- onStream nextByte ~~ b ifTrue:[ self zerror:'version error' ]
- ].
+ GZ_MAGIC_ID do:[:b|
+ onStream nextByte ~~ b ifTrue:[ self zerror:'version error' ]
+ ].
- onStream nextByte ~~ Z_DEFLATED ifTrue:[
- self zerror:'invalid method (not deflated)'
- ].
+ onStream nextByte ~~ Z_DEFLATED ifTrue:[
+ self zerror:'invalid method (not deflated)'
+ ].
- flags := onStream nextByte.
- (flags bitAnd:HEAD_RESERVED) ~~ 0 ifTrue:[
- self zerror:'wrong data format'
- ].
+ flags := onStream nextByte.
+ (flags bitAnd:HEAD_RESERVED) ~~ 0 ifTrue:[
+ self zerror:'wrong data format'
+ ].
- "discard time, xflags and OS code"
- onStream skip:6.
+ "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 ].
- ].
+ (flags bitAnd:HEAD_EXTRA_FIELD) ~~ 0 ifTrue:[|len|
+ "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.
- ].
+ (flags bitAnd:HEAD_ORIG_NAME) ~~ 0 ifTrue:[|b|
+ "skip the original file name"
+ [ (b := onStream nextByte) ~~ 0 ] whileTrue.
+ ].
- (flags bitAnd:HEAD_CRC) ~~ 0 ifTrue:[
- "skip the header crc"
- onStream skip:2.
- ].
+ (flags bitAnd:HEAD_CRC) ~~ 0 ifTrue:[
+ "skip the header crc"
+ onStream skip:2.
+ ].
] ifFalse:[
- "write the gzip magic id
- "
- GZ_MAGIC_ID do:[:b| onStream nextPutByte:b ].
+ "write the gzip magic id
+ "
+ GZ_MAGIC_ID do:[:b| onStream nextPutByte:b ].
- "write the method"
- onStream nextPutByte:Z_DEFLATED.
+ "write the method"
+ onStream nextPutByte:Z_DEFLATED.
- "write the flags"
- onStream nextPutByte:0.
+ "write the flags"
+ onStream nextPutByte:0.
- "write time"
- 4 timesRepeat:[ onStream nextPutByte:0 ].
+ "write time"
+ 4 timesRepeat:[ onStream nextPutByte:0 ].
- "write xflags"
- onStream nextPutByte:0.
+ "write xflags"
+ onStream nextPutByte:0.
- "write OS code"
- onStream nextPutByte:HEAD_OS_CODE.
+ "write OS code"
+ onStream nextPutByte:HEAD_OS_CODE.
].
! !
!ZipStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/ZipStream.st,v 1.28 2007-02-15 14:46:40 sr Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/ZipStream.st,v 1.29 2008-06-05 09:16:16 ab Exp $'
! !
ZipStream initialize!