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.55 date: 2022/05/11 13:57:13
user: stefan
file: ZipStream.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


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


[instance variables:]

[class variables:]

copyright

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

Class protocol:

ZipInterface compatibility - compress/uncompress
o  compress: anUncompressedByteArrayOrString
compress anUncompressedByteArrayOrString and return it

Usage example(s):

     self compress:'hello world hello world hello world hello world hello world'.

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

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
uncompress aCompressedByteArrayOrString into anUncompressedByteArrayOrString;
return the number of bytes in the destination buffer

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

class 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.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 23 Nov 2024 08:01:37 GMT