eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'ZipStream':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: ZipStream


Inheritance:

   Object
   |
   +--Stream
      |
      +--CompressionStream
         |
         +--ZipStream

Package:
stx:libbasic2
Category:
Streams-Compressed
Version:
rev: 1.49 date: 2018/12/18 11:52:15
user: cg
file: ZipStream.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
Claus Atzkern

Description:


Zip compression and decompression (as used in gzip and zip)


[instance variables:]

[class variables:]


Related information:



Class protocol:

ZipInterface compatibility - compress/uncompress
o  compress: anUncompressedByteArrayOrString into: aCompressedByteArrayOrString
|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.

o  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

o  uncompress: aCompressedByteArrayOrString into: anUncompressedByteArrayOrString
Modified (format): / 18-12-2018 / 12:53:09 / Claus Gittinger

ZipInterface compatibility - crc
o  crc32Add: aCharacterOrByte crc: crc
Update a running crc with aCharacterOrByte
and return the updated crc

o  crc32BytesIn: bytesIn from: start to: stop crc: crc
Update a running crc with the bytes buf[start.. stop]
and return the updated crc

initialization
o  initialize
setup class attributes derived from the library

instance creation
o  readOpenAsZipStreamOn: aStream
open to read data compressed from stream,
the default readOpenOn: will open ZipStream as gzip stream

o  readOpenAsZipStreamOn: aStream suppressFileHeader: suppressFileHeader suppressZipHeaderAndChecksum: suppressZipHeaderAndChecksum
open to read data compressed from stream,
the default readOpenOn: will open ZipStream as gzip stream

o  readOpenAsZipStreamOn: aStream suppressHeaderAndChecksum: aBoolean
open to read data compressed from stream,
the default readOpenOn: will open ZipStream as gzip stream

o  writeOpenAsZipStreamOn: aStream
open to write data compressed to stream,
the default writeOpenOn: will open ZipStream as gzip stream

o  writeOpenAsZipStreamOn: aStream suppressFileHeader: suppressFileHeader suppressZipHeaderAndChecksum: suppressZipHeaderAndChecksum
open to write data compressed to stream,
the default writeOpenOn: will open ZipStream as gzip stream

o  writeOpenAsZipStreamOn: aStream suppressHeaderAndChecksum: aBoolean
open to write data compressed to stream,
the default writeOpenOn: will open ZipStream as gzip stream

queries
o  maxDistanceCodes

o  maxLiteralCodes


Instance protocol:

low level
o  zclose
low level close of the zip stream

o  zdeflate
low level - deflate

o  zdeflateInit
low level - deflateInit

o  zget_avail_out
low level - get the number of available out bytes

o  zget_windowBits
answer the bits used for inflateInit2 or deflateInit2...
a negative WindowBits value suppresses the zlib header and the checksum...

o  zinflate
low level - inflate

o  zinflateInit
low level - inflateInit

o  zopen
low level - opens the zip stream

o  zset_avail_in: count
set the 'avail_in' and compute the crc

startup & release
o  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

o  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)

o  readHeader
Check for the gzip magic id

o  writeHeader
write the gzip magic id


Examples:


    |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.


ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Mon, 21 Jun 2021 01:29:38 GMT