|
Class: ZipStream
Object
|
+--Stream
|
+--CompressionStream
|
+--ZipStream
- Package:
- stx:libbasic2
- Category:
- Streams-Compressed
- Version:
- rev:
1.55
date: 2022/05/11 13:57:13
- user: stefan
- file: ZipStream.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
Zip compression and decompression (as used in gzip and zip)
[instance variables:]
[class variables:]
copyrightCOPYRIGHT (c) 2002 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
ZipInterface compatibility - compress/uncompress
-
compress: anUncompressedByteArrayOrString
-
compress anUncompressedByteArrayOrString and return it
Usage example(s):
self compress:'hello world hello world hello world hello world hello world'.
|
-
compress: anUncompressedByteArrayOrString into: aCompressedByteArrayOrString
-
compress anUncompressedByteArrayOrString into aCompressedByteArrayOrString;
return the number of bytes in the destination buffer
Usage example(s):
|buffer len1 len2 compressed uncompressed|
buffer := String new:100.
len1 := self compress:'hello world hello world hello world hello world hello world' into:buffer.
compressed := buffer copyTo:len1.
len2 := self uncompress:compressed into:buffer.
uncompressed := buffer copyTo:len2.
|
-
flatBytesIn: bytesIn from: start to: stop into: bytesOut doCompress: doCompress
-
compress or uncompress the bytesIn buffer into the bytesOut buffer;
returns the un/compressed size; on error an exception is raised
-
uncompress: aCompressedByteArrayOrString into: anUncompressedByteArrayOrString
-
uncompress aCompressedByteArrayOrString into anUncompressedByteArrayOrString;
return the number of bytes in the destination buffer
-
uncompressRaw: bytesIn from: start to: stop into: bytesOut
-
uncompress the bytesIn buffer into the bytesOut buffer;
returns the uncompressed size; on error an exception is raised.
Raw means: do not expect a zlib or gzip header and checksum in bytesIn.
ZipInterface compatibility - crc
-
crc32Add: aCharacterOrByte crc: crc
-
Update a running crc with aCharacterOrByte
and return the updated crc
-
crc32BytesIn: bytesIn from: start to: stop crc: crc
-
Update a running crc with the bytes buf[start.. stop]
and return the updated crc
class initialization
-
initialize
-
setup class attributes derived from the library
instance creation
-
readOpenAsZipStreamOn: aStream
-
open to read data compressed from stream,
the default readOpenOn: will open ZipStream as gzip stream
-
readOpenAsZipStreamOn: aStream suppressFileHeader: suppressFileHeader suppressZipHeaderAndChecksum: suppressZipHeaderAndChecksum
-
open to read data compressed from stream,
the default readOpenOn: will open ZipStream as gzip stream
-
readOpenAsZipStreamOn: aStream suppressHeaderAndChecksum: aBoolean
-
open to read data compressed from stream,
the default readOpenOn: will open ZipStream as gzip stream
-
writeOpenAsZipStreamOn: aStream
-
open to write data compressed to stream,
the default writeOpenOn: will open ZipStream as gzip stream
-
writeOpenAsZipStreamOn: aStream suppressFileHeader: suppressFileHeader suppressZipHeaderAndChecksum: suppressZipHeaderAndChecksum
-
open to write data compressed to stream,
the default writeOpenOn: will open ZipStream as gzip stream
-
writeOpenAsZipStreamOn: aStream suppressHeaderAndChecksum: aBoolean
-
open to write data compressed to stream,
the default writeOpenOn: will open ZipStream as gzip stream
queries
-
maxDistanceCodes
-
-
maxLiteralCodes
-
low level
-
zclose
-
low level close of the zip stream
-
zdeflate
-
low level - deflate
-
zdeflateInit
-
low level - deflateInit
-
zget_avail_out
-
low level - get the number of available out bytes
-
zget_windowBits
-
answer the bits used for inflateInit2 or deflateInit2...
a negative WindowBits value suppresses the zlib header and the checksum...
-
zinflate
-
low level - inflate
-
zinflateInit
-
low level - inflateInit
-
zopen
-
low level - opens the zip stream
-
zset_avail_in: count
-
set the 'avail_in' and compute the crc
startup & release
-
openWithMode: aMode on: aStream suppressFileHeader: suppressFileHeader suppressZipHeaderAndChecksum: suppressZipHeaderAndChecksum
-
open stream and write or check gzip header
suppressFileHeader:
if true, the gzip header (magic number and a few extra fields) is not written/read
suppressZipHeaderAndChecksum
controls if the gzip checksum and 2 header bytes should be written/checked
-
openWithMode: aMode on: aStream suppressHeaderAndChecksum: aBoolean
-
open stream and write or check gzip header.
Caveat:
Backward compatibility: aBoolean controls if the gzip checksum and 2 header bytes should be written/checked
(i.e. NOT the file header with the zip magic)
-
readHeader
-
Check for the gzip magic id
-
writeHeader
-
write the gzip magic id
|compressedDataStream zipStream compressedData uncompressedData|
compressedDataStream := #[] writeStream.
zipStream := ZipStream writeOpenOn:compressedDataStream.
zipStream nextPutAll:'hallo Welt'.
zipStream close.
compressedData := compressedDataStream contents.
zipStream := ZipStream readOpenOn:(compressedData readStream).
zipStream notNil ifTrue:[
|stream c|
stream := '' writeStream.
[ (c := zipStream nextOrNil) notNil ] whileTrue:[
stream nextPut:c
].
stream close.
uncompressedData := stream contents.
].
^ uncompressedData
|
|fstream zipStream c|
fstream := FileStream newTemporary.
zipStream := ZipStream writeOpenOn:fstream.
zipStream nextPutAll:'hallo Welt(1) - test....'.
zipStream cr.
zipStream nextPutAll:'hallo Welt(2) - test....'.
zipStream cr.
zipStream close.
fstream close.
fstream := fstream fileName readStream.
zipStream := ZipStream readOpenOn:fstream.
Transcript showCR:zipStream contents.
zipStream close.
fstream close.
fstream fileName delete.
|
|