From VisualWorks®, 7.6 of February 1, 2008 on February 1, 2008 at 12:29:08 pm (Dialog confirm: 'You are filing-in a Parcel source file!\\While this is possible it will not have\the same effect as loading the parcel.\None of the Parcel''s prerequisites will\be loaded and none of its load actions\will be performed.\\Are you sure you want to file-in?' withCRs) ifFalse: [self error: 'Parcel file-in abandoned. Choose terminate or close.'] <name>ZLib</name> <environment>OS</environment> <private>false</private> <imports> Core.* External.* OS.* </imports> <category>Net-Namespace</category> <attributes> <package>Compression-ZLib</package> </attributes> <comment> OS.ZLib
The ZLib NameSpace contains the VisualWorks ZLib library interface and supporting classes.
</comment> <class> <name>DeflateStream</name> <environment>OS.ZLib</environment> <super>Core.WriteStream</super> <private>false</private> none outputBuffer interface destinationStream compressionLevel <imports></imports> <category>Compression-ZLib</category> <attributes> <package>Compression-ZLib</package> </attributes> </class> <comment> OS.ZLib.DeflateStream
DeflateStream is an abstract read stream that compresses byte streams using the same zlib facilities the engine uses to decompress compressed images. A DeflateStream is created on some sequenceable collection of bytes (e.g. ByteArray) or write stream of bytes. Writing to the stream via nextPut: et al causes compressed data to be written to the collection or stream. By default the data are a stream of bytes, but if sent text the stream will accept a stream of single-byte characters. Internally, the stream's collection is the input buffer and is used to hold up to a BufferSize's worth of uncompressed data for accessing via nextPut: et al by clients of the stream. Its concrete subclasses add the decoding of appropriate header information. subclass responsibilities writeHeader finishOutput Instance Variables: outputBuffer <ByteArray> fixed-space buffer for passing output from the compression routines to the destinationStream interface <ZLibInterface> the external interface to the ZLib C code in the engine destinationStream <WriteStream> the stream holding the compressed data compressionLevel <Integer | nil> the compression level to use in compressing the input data Shared Class Variables: BufferSize <Integer> maximum number of bytes to be processed with one zlib call
</comment> <class> <name>InflateStream</name> <environment>OS.ZLib</environment> <super>Core.ReadStream</super> <private>false</private> none inputBuffer inputLimit interface sourceStream superPosition eof <imports></imports> <category>Compression-ZLib</category> <attributes> <package>Compression-ZLib</package> </attributes> </class> <comment> OS.ZLib.InflateStream
InflateStream is a stream that decompresses using the same zlib facilities the engine uses to decompress compressed images. InflateStreams are created on some input ByteArray or read stream answering bytes. Reading the stream answers the decompressed form of the compressed data in the original collection or stream. By default the data are a stream of bytes, but if sent text the stream will supply a stream of single-byte characters. Internally, the stream's collection is the output buffer and is used to hold a BufferSize's worth of decompressed data for accessing via next et al by clients of the stream. The output bufffer is filled on demand from pastEnd. position is therefore only the position into the output buffer, not the actual position in the output stream. subclass responsibilities checkHeader Instance Variables: inputBuffer <ByteArray> fixed-space buffer for passing input from the sourceStream to the decompression routines, i.e. it contains chunks of the compressed data inputLimit <Integer> index of the last valid data in inputBuffer interface <ZLibInterface> the external interface to the ZLib C code in the engine sourceStream <ReadStream> the data to decompress superPosition <Integer> the position in the decompressed output eof <Boolean> an flag indicating whether we have reached the end of the compressed data (i.e. ZLib signalled Z_STREAM_END) Shared Class Variables: BufferSize <Integer> maximum number of bytes to be processed with one zlib call
</comment> <class> <name>GZipWriteStream</name> <environment>OS.ZLib</environment> <super>OS.ZLib.DeflateStream</super> <private>false</private> none crc <imports></imports> <category>Compression-ZLib</category> <attributes> <package>Compression-ZLib</package> </attributes> </class> <comment> OS.ZLib.GZipWriteStream
GZipWriteStream is a concrete subclass of DeflateStream that compresses data in the format used by gzip. GZip's home site is http://www.gzip.org/. To use, create a GZipWriteStream on some output stream or data write to the GZipWrite stream to store compressed data on the output stream. | output | (output := 'myfile.gz' asFilename writeStream) binary. (GZipWriteStream bestCompressionOn: output) nextPutAll: 'hello world' asByteArray readStream; close
</comment> <class> <name>ZLibInterface</name> <environment>OS.ZLib</environment> <super>External.ExternalInterface</super> <private>false</private> none zstream errno heap <imports> OS.ZLib.ZLibInterfaceDictionary.* </imports> <category>Compression-ZLib</category> <attributes> <includeFiles><item>zlib.h</item></includeFiles> <includeDirectories><item>/usr/include</item></includeDirectories> <libraryFiles></libraryFiles> <libraryDirectories></libraryDirectories> false full <package>Compression-ZLib</package> </attributes> </class> <comment> OS.ZLib.ZLibInterface
ZLibInterface provides a low level binding to the zlib library which is included in the engine to support image decompression on loading. ZLib is written by Jean-loup Gailly and Mark Adler. ZLib's home site is http://www.gzip.org/zlib/ and is described in http://www.gzip.org/zlib/manual.html. The data format used by the zlib library is described by RFCs (Request for Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). The clients of this class must have a thorough understanding of the zlib library and its appropriate use. We recommend you make use of the compression streams InflateStream, DeflateStream and their subclasses.
</comment> <class> <name>GZipReadStream</name> <environment>OS.ZLib</environment> <super>OS.ZLib.InflateStream</super> <private>false</private> none checkCrc crc <imports></imports> <category>Compression-ZLib</category> <attributes> <package>Compression-ZLib</package> </attributes> </class> <comment> OS.ZLib.GZipReadStream
GZipReadStream is a concrete subclass of InflateStream that decompresses data in the format used by gzip. GZip's home site is http://www.gzip.org/. To use, create a stream on some compressed data in gzip format and read from the stream to get decompressed data. For example | input | (input := 'myfile.gz' asFilename readStream) binary. (GZipReadStream on: input) contents
</comment> <name>BufferSize</name> <environment>OS.ZLib.InflateStream</environment> <private>false</private> <constant>true</constant> <category>constants</category> <initializer>16384</initializer> <attributes> <package>Compression-ZLib</package> </attributes> <name>GZipContinueFlag</name> <environment>OS.ZLib</environment> <private>false</private> <constant>true</constant> <category>Constants</category> <initializer> "Part of a multi-part archive" 16r2</initializer> <attributes> <package>Compression-ZLib</package> </attributes> <name>GZipNameFlag</name> <environment>OS.ZLib</environment> <private>false</private> <constant>true</constant> <category>Constants</category> <initializer> "Archive has original file name" 16r8</initializer> <attributes> <package>Compression-ZLib</package> </attributes> <name>GZipEncryptFlag</name> <environment>OS.ZLib</environment> <private>false</private> <constant>true</constant> <category>Constants</category> <initializer> "Archive is encrypted" 16r20</initializer> <attributes> <package>Compression-ZLib</package> </attributes> <name>GZipMagic</name> <environment>OS.ZLib</environment> <private>false</private> <constant>true</constant> <category>Constants</category> <initializer> "GZIP magic number" 16r8B1F</initializer> <attributes> <package>Compression-ZLib</package> </attributes> <name>ZLibInterfaceDictionary</name> <environment>OS.ZLib</environment> <private>false</private> <constant>false</constant> <category>As yet unclassified</category> <attributes> <package>Compression-ZLib</package> </attributes> <name>GZipCommentFlag</name> <environment>OS.ZLib</environment> <private>false</private> <constant>true</constant> <category>Constants</category> <initializer> "Archive has comment" 16r10</initializer> <attributes> <package>Compression-ZLib</package> </attributes> <name>GZipDeflated</name> <environment>OS.ZLib</environment> <private>false</private> <constant>true</constant> <category>Constants</category> <initializer> "Compression method" 16r8</initializer> <attributes> <package>Compression-ZLib</package> </attributes> <name>GZipReservedFlags</name> <environment>OS.ZLib</environment> <private>false</private> <constant>true</constant> <category>Constants</category> <initializer> "Reserved" 16rC0</initializer> <attributes> <package>Compression-ZLib</package> </attributes> <name>GZipAsciiFlag</name> <environment>OS.ZLib</environment> <private>false</private> <constant>true</constant> <category>Constants</category> <initializer> "Contents is ASCII" 16r1</initializer> <attributes> <package>Compression-ZLib</package> </attributes> <name>GZipExtraField</name> <environment>OS.ZLib</environment> <private>false</private> <constant>true</constant> <category>Constants</category> <initializer> "Archive has extra fields" 16r4</initializer> <attributes> <package>Compression-ZLib</package> </attributes> <name>BufferSize</name> <environment>OS.ZLib.DeflateStream</environment> <private>false</private> <constant>true</constant> <category>constants</category> <initializer>16384</initializer> <attributes> <package>Compression-ZLib</package> </attributes> <name>HeapSize</name> <environment>OS.ZLib.ZLibInterface</environment> <private>false</private> <constant>true</constant> <category>constants</category> <initializer>"ZLib limits its memory usage to 256K. We allow an additional 32k for heap overhead; a 12.5% overhead." 9 * 32 * 1024</initializer> <attributes> <package>Compression-ZLib</package> </attributes> <methods> OS.ZLib.DeflateStream <category>testing</category>
atEnd "The receiver is always at the end." ^true
</methods> <methods> OS.ZLib.DeflateStream <category>accessing</category>
compressionLevel compressionLevel == nil ifTrue: [compressionLevel := ZLibInterface Z_DEFAULT_COMPRESSION]. ^compressionLevel
compressionLevel: anInteger (anInteger between: ZLibInterface Z_BEST_SPEED and: ZLibInterface Z_BEST_COMPRESSION) ifFalse: [self error: 'invalid compression level']. compressionLevel := anInteger
flush "Write any unwritten information." self writeBuffer: true
next: anInteger putAll: aSequenceableCollection startingAt: startIndex "Store the anInteger elements of aSequenceableCollection starting at startIndex into the next anInteger elements of the receiver. Answer aSequenceableCollection" | howManyWritten | anInteger > 1 ifFalse: [anInteger = 1 ifTrue: [self nextPut: (aSequenceableCollection at: startIndex)]. ^aSequenceableCollection]. position >= writeLimit ifTrue: [self writeBuffer: false]. howManyWritten := 0. [| increment newPosition | increment := (writeLimit - position) min: (anInteger - howManyWritten). newPosition := position + increment. collection replaceFrom: position + 1 to: newPosition with: aSequenceableCollection startingAt: startIndex + howManyWritten. position := newPosition. howManyWritten := howManyWritten + increment. howManyWritten < anInteger] whileTrue: [self writeBuffer: false]. ^aSequenceableCollection
nextPutBufferFrom: aStream "Read the next buffer's worth from aStream. Avoid copying overhead by reading directly into the collection if possible." position > 0 ifTrue: [self writeBuffer: false]. [aStream next: BufferSize into: collection startingAt: 1. position := BufferSize] on: IncompleteNextCountError do: [:ex| position := ex parameter]. self writeBuffer: aStream atEnd
</methods> <methods> OS.ZLib.DeflateStream <category>private</category>
finishBuffer | result | self writeBuffer: false. [ interface avail_out < BufferSize ifTrue: [ destinationStream next: BufferSize - interface avail_out putAll: outputBuffer startingAt: 1. interface next_out: outputBuffer fixedHeapAddress; avail_out: BufferSize]. result := interface cDeflate: interface zstream flush: interface Z_FINISH. (result ~= interface Z_OK and: [result ~= interface Z_STREAM_END]) ifTrue: [ "ignore the second of two consecutive flushes:" (interface avail_out == BufferSize and: [result = interface Z_BUF_ERROR]) ifTrue: [result := interface Z_OK] ifFalse: [self error: #ZLibDeflateError << #dialogs >> 'deflate error']]. interface avail_out ~= BufferSize or: [result ~= interface Z_STREAM_END] ] whileTrue. destinationStream flush
finishOutput self subclassResponsibility
on: aCollectionOrStream destinationStream := (aCollectionOrStream isSequenceable) ifTrue: [aCollectionOrStream writeStream] ifFalse:[aCollectionOrStream]. self writeHeader. self setupBufferAndLimits
on: aCollectionOrStream compressionLevel: anInteger self compressionLevel: anInteger. self on: aCollectionOrStream
pastEndPut: anObject "Compress (flush) the collection." self writeBuffer: false. self nextPut: anObject
setupBufferAndLimits "Initialize the ioBuffer and limits." | result | interface := ZLibInterface newUsingEngineAllocator. outputBuffer := ByteArray newInFixedSpace: BufferSize. collection := ByteArray newInFixedSpace: BufferSize. result := true ifTrue: [interface cDeflateInit2: interface zstream level: self compressionLevel method: interface Z_DEFLATED windowBits: interface MAX_WBITS negated memLevel: interface DEF_MEM_LEVEL strategy: interface Z_DEFAULT_STRATEGY version: interface version streamSize: interface z_stream dataSize] ifFalse: [interface deflateInit: self compressionLevel]. result ~= interface Z_OK ifTrue: [self error: 'zlib deflateInit: initialization failed']. interface next_out: outputBuffer fixedHeapAddress; avail_out: BufferSize. position := 0. readLimit := -1. writeLimit := BufferSize
writeBuffer: flush | result maxedOut | maxedOut := false. interface avail_in: position; next_in: collection fixedHeapAddress. [interface avail_in > 0 or: [maxedOut]] whileTrue: [result := interface cDeflate: interface zstream flush: (flush ifTrue: [ interface Z_SYNC_FLUSH ] ifFalse: [ interface Z_NO_FLUSH ]). maxedOut := interface avail_out = 0. (result = interface Z_OK or: [result = interface Z_BUF_ERROR and: [maxedOut]]) ifFalse: [self error: #ZLibDeflateError << #dialogs >> 'deflate error']. interface avail_out < BufferSize ifTrue: [destinationStream next: BufferSize - interface avail_out putAll: outputBuffer startingAt: 1. interface next_out: outputBuffer fixedHeapAddress; avail_out: BufferSize]]. position := 0. writeLimit := BufferSize. flush ifTrue: [ destinationStream flush ]
writeHeader self subclassResponsibility
</methods> <methods> OS.ZLib.DeflateStream <category>positioning</category>
position "Answer the receiver's position." ^position + interface total_in
position: anInteger self error: 'compression streams are not positionable'
</methods> <methods> OS.ZLib.DeflateStream <category>status</category>
close "Close the destination stream and write any unwritten information." self finishBuffer. self finishOutput. destinationStream close
</methods> <methods> OS.ZLib.DeflateStream <category>stream modes</category>
binary "Change the stream to receive bytes. Note that the following test avoids changing collection's class when collection is nil." (collection isKindOf: ByteEncodedString) ifTrue: [collection changeClassTo: ByteArray]
text "Change the stream to receive characters. Note that the following test avoids changing collection's class when collection is nil." collection class == ByteArray ifTrue: [collection changeClassTo: String defaultPlatformClass]
</methods> <methods> OS.ZLib.DeflateStream class <category>instance creation</category>
bestCompressionOn: aCollectionOrStream ^self basicNew on: aCollectionOrStream compressionLevel: ZLibInterface Z_BEST_COMPRESSION
on: aCollectionOrStream compressionLevel: anInteger ^self basicNew on: aCollectionOrStream compressionLevel: anInteger
</methods> <methods> OS.ZLib.InflateStream <category>testing</category>
atEnd "Answer true if the position is greater than or equal to the limit, otherwise answer false. " ^self basicAtEnd and: [self endTest]
</methods> <methods> OS.ZLib.InflateStream <category>private</category>
basicAtEnd "Answer true if the position is greater than or equal to the limit, otherwise answer false. Fail if position or readLimit is not a SmallInteger and answer true. Only called by atEnd which will continue processing if true is returned in order to handle streaming across buffer boundries." <primitive: 67> ^true
checkHeader self subclassResponsibility
endTest "Answer true if the receiver is at the end of the data, if not get the next buffer. Used by atEnd" position < readLimit ifTrue: [^false]. self nextBuffer ifFalse: [^true]. ^position = readLimit
fillInputBuffer "Fill the input buffer with as much data as possible. First move any unconsumed data to the beginning of the buffer, then read into the buffer if there is room, and reset the input pointers." | remaining consumed | (remaining := interface avail_in) > 0 ifTrue: [consumed := interface next_in datum - inputBuffer fixedHeapAddress. consumed > 0 ifTrue: [inputBuffer replaceFrom: 1 to: remaining with: inputBuffer startingAt: consumed + 1. inputLimit := remaining]]. remaining < BufferSize ifTrue: [[sourceStream next: BufferSize - remaining into: inputBuffer startingAt: remaining + 1. inputLimit := BufferSize] on: IncompleteNextCountError do: [:ex| inputLimit := ex parameter + remaining]]. interface next_in: inputBuffer fixedHeapAddress; avail_in: inputLimit
nextBuffer | result | interface next_out datum = 0 ifTrue: [interface next_out: collection fixedHeapAddress; avail_out: BufferSize]. (interface avail_out > 0 and: [eof not]) ifTrue: [self fillInputBuffer. superPosition := interface total_out. eof := (result := interface inflateNoFlush) = interface Z_STREAM_END]. readLimit := interface next_out datum - collection fixedHeapAddress. interface next_out: 0. position := 0. ^readLimit > 0
on: aCollectionOrStream sourceStream := aCollectionOrStream isSequenceable ifTrue: [aCollectionOrStream readStream] ifFalse: [aCollectionOrStream]. self setupBufferAndLimits. self checkHeader
pastEnd "Raise a signal if the receiver is at the end of the data, if not get the next buffer and return the next element." position < readLimit ifTrue: [^collection at: (position := position + 1)]. ^self nextBuffer ifTrue: [collection at: (position := position + 1)] ifFalse: [self class endOfStreamSignal raiseRequestFrom: self]
setupBufferAndLimits "Initialize the ioBuffer and limits." | result | interface := ZLibInterface newUsingEngineAllocator. inputBuffer := ByteArray newInFixedSpace: BufferSize. collection := ByteArray newInFixedSpace: BufferSize. (result := interface cInflateInit2: interface zstream windowBits: interface MAX_WBITS negated version: interface version streamSize: interface z_stream dataSize) ~= interface Z_OK ifTrue: [self error: #ZlibInflateInit2Failed << #dialogs >> 'zlib inflateInit2 initialization failed']. position := superPosition := 0. readLimit := 0. writeLimit := -1. eof := false
</methods> <methods> OS.ZLib.InflateStream <category>accessing</category>
contents | contents | contents := (self contentsSpecies new: sourceStream size) writeStream. [self atEnd] whileFalse: [contents nextPut: self next]. ^contents contents
next: anInteger into: aSequenceableCollection startingAt: startIndex "Store the next anInteger elements of the receiver into aSequenceableCollection starting at startIndex in aSequenceableCollection. Answer aSequenceableCollection." | howManyRead increment newHowManyRead | howManyRead := 0. [howManyRead < anInteger] whileTrue: [self atEnd ifTrue: [^Stream incompleteNextCountSignal raiseRequestWith: howManyRead]. increment := (readLimit - position) min: (anInteger - howManyRead). newHowManyRead := howManyRead + increment. aSequenceableCollection replaceFrom: startIndex + howManyRead to: startIndex - 1 + newHowManyRead with: collection startingAt: position + 1. position := position + increment. howManyRead := newHowManyRead]. ^aSequenceableCollection
sourceStream ^sourceStream
</methods> <methods> OS.ZLib.InflateStream <category>positioning</category>
position "Answer the receiver's position." ^position + superPosition
position: anInteger self error: 'decompression streams are not positionable'
skip: anInteger "Set position to position+anInteger." | remaining | remaining := anInteger. [remaining > 0] whileTrue: [position + remaining > BufferSize ifTrue: [remaining := remaining - (BufferSize - position) - 1. position := BufferSize. self next] ifFalse: [position := position + remaining. remaining := 0]]
</methods> <methods> OS.ZLib.InflateStream <category>status</category>
close self sourceStream close
</methods> <methods> OS.ZLib.InflateStream <category>nonhomogeneous positioning</category>
padTo: bsize "Pad (skip) to next boundary of bsize characters, and answer how many characters were skipped." | rem | rem := bsize - (self position \\ bsize). rem = bsize ifTrue: [^0]. self skip: rem. ^rem
</methods> <methods> OS.ZLib.InflateStream <category>stream modes</category>
binary "Change the stream to receive bytes. Note that the following test avoids changing collection's class when collection is nil." (collection isKindOf: ByteEncodedString) ifTrue: [collection changeClassTo: ByteArray]
text "Change the stream to receive characters. Note that the following test avoids changing collection's class when collection is nil." collection class == ByteArray ifTrue: [collection changeClassTo: String defaultPlatformClass]
</methods> <methods> OS.ZLib.GZipWriteStream <category>private</category>
finishOutput | total_in | 1 to: 4 do: [:i| destinationStream nextPut: (crc digitAt: i)]. total_in := interface total_in. 1 to: 4 do: [:i| destinationStream nextPut: (total_in digitAt: i)].
setupBufferAndLimits super setupBufferAndLimits. crc := interface cCrc32: 0 buffer: 0 length: 0
writeBuffer: flush position > 0 ifTrue: [crc := interface cCrc32: crc buffer: collection fixedHeapAddress length: position]. ^super writeBuffer: flush.
writeHeader destinationStream nextPut: (GZipMagic digitAt: 1); nextPut: (GZipMagic digitAt: 2); nextPut: GZipDeflated; next: 7 put: 0
</methods> <methods> OS.ZLib.ZLibInterface <category>types</category>
alloc_func <C: typedef voidpf (*alloc_func)(voidpf, uInt, uInt)>
Bytef <C: typedef unsigned char Bytef>
free_func <C: typedef void (*free_func)(voidpf, voidpf)>
gzFile <C: typedef void * gzFile>
uInt <C: typedef unsigned int uInt>
uLong <C: typedef unsigned long uLong>
voidpf <C: typedef void * voidpf>
z_off_t <C: typedef long z_off_t>
z_stream <C: typedef struct { Bytef *next_in; uInt avail_in; uLong total_in; Bytef *next_out; uInt avail_out; uLong total_out; char *msg; void *state; alloc_func zalloc; free_func zfree; voidpf opaque; int data_type; uLong adler; uLong reserved; } z_stream>
z_streamp <C: typedef z_stream * z_streamp>
</methods> <methods> OS.ZLib.ZLibInterface <category>accessing-zstream</category>
avail_in ^self zstream memberAt: #'avail_in'
avail_in: anInteger ^self zstream memberAt: #'avail_in' put: anInteger
avail_out ^self zstream memberAt: #'avail_out'
avail_out: anInteger ^self zstream memberAt: #'avail_out' put: anInteger
data_type ^self zstream memberAt: #'data_type'
next_in ^self zstream memberAt: #'next_in'
next_in: aPointer ^self zstream memberAt: #'next_in' put: aPointer
next_out ^self zstream memberAt: #'next_out'
next_out: aPointer ^self zstream memberAt: #'next_out' put: aPointer
opaque: aPointerOrNil ^self zstream memberAt: #'opaque' put: aPointerOrNil
total_in ^self zstream memberAt: #'total_in'
total_in: anInteger ^self zstream memberAt: #'total_in' put: anInteger
total_out ^self zstream memberAt: #'total_out'
total_out: anInteger ^self zstream memberAt: #'total_out' put: anInteger
zalloc ^self zstream memberAt: #'zalloc'
zalloc: aFunctionPointerOrNil ^self zstream memberAt: #'zalloc' put: aFunctionPointerOrNil
zfree ^self zstream memberAt: #'zfree'
zfree: aFunctionPointerOrNil ^self zstream memberAt: #'zfree' put: aFunctionPointerOrNil
</methods> <methods> OS.ZLib.ZLibInterface <category>deflating</category>
deflate: flushCode errno := self cDeflate: self zstream flush: flushCode. ((errno == self Z_OK) or: [errno == self Z_STREAM_END]) ifFalse: [self error: (self errorStringFor: errno)]. ^errno
deflateFinish ^self deflate: self Z_FINISH
deflateFullFlush ^self deflate: self Z_FULL_FLUSH
deflateNoFlush ^self deflate: self Z_NO_FLUSH
deflateSyncFlush ^self deflate: self Z_SYNC_FLUSH
</methods> <methods> OS.ZLib.ZLibInterface <category>deflate-setup teardown</category>
deflateEnd errno := self cDeflateEnd: self zstream. errno ~~ self Z_OK ifTrue: [self error: (self errorStringFor: errno)]. ^errno
deflateInit ^self deflateInit: self Z_DEFAULT_COMPRESSION
deflateInit: levelCode "Initialize the zlib compression engine." errno := self cDeflateInit: self zstream level: levelCode version: self zlibVersion streamSize: self z_stream dataSize. errno ~~ self Z_OK ifTrue: [self error: (self errorStringFor: errno)]. ^errno
deflateInitBestCompression ^self deflateInit: self Z_BEST_COMPRESSION
deflateInitBestSpeed ^self deflateInit: self Z_BEST_SPEED
deflateInitNoCompression ^self deflateInit: self Z_NO_COMPRESSION
</methods> <methods> OS.ZLib.ZLibInterface <category>accessing-zlib constants</category>
DEF_MEM_LEVEL ^8
errorStringFor: errorCode ^(errorCode between: self Z_VERSION_ERROR and: self Z_NEED_DICT) ifTrue: [(self cZError: errorCode) copyCStringFromHeap] ifFalse: ['unknown error ', errorCode printString] "| i | i := self new. (i Z_VERSION_ERROR to: i Z_NEED_DICT) collect: [:ec| i errorStringFor: ec]"
MAX_WBITS ^15
SEEK_CUR ^1
SEEK_END ^2
SEEK_SET ^0
Z_ASCII ^1
Z_BEST_COMPRESSION ^9
Z_BEST_SPEED ^1
Z_BINARY ^0
Z_BUF_ERROR ^-5
Z_DATA_ERROR ^-3
Z_DEFAULT_COMPRESSION ^-1
Z_DEFAULT_STRATEGY ^0
Z_DEFLATED ^8
Z_ERRNO ^-1
Z_FILTERED ^1
Z_FINISH ^4
Z_FULL_FLUSH ^3
Z_HUFFMAN_ONLY ^2
Z_MEM_ERROR ^-4
Z_NEED_DICT ^2
Z_NO_COMPRESSION ^0
Z_NO_FLUSH ^0
Z_OK ^0
Z_PARTIAL_FLUSH ^1
Z_STREAM_END ^1
Z_STREAM_ERROR ^-2
Z_SYNC_FLUSH ^2
Z_UNKNOWN ^2
Z_VERSION_ERROR ^-6
</methods> <methods> OS.ZLib.ZLibInterface <category>accessing</category>
errno "Answer the last c call return code issued." ^errno
version ^self zlibVersion copyCStringFromHeap
zstream zstream == nil ifTrue: [zstream := self z_stream gcCalloc]. ^zstream
</methods> <methods> OS.ZLib.ZLibInterface <category>inflating</category>
inflate: flushCode errno := self cInflate: self zstream flush: flushCode. ((errno == self Z_OK) or: [errno == self Z_STREAM_END]) ifFalse: [self error: (self errorStringFor: errno)]. ^errno
inflateFinish ^self inflate: self Z_FINISH
inflateFullFlush ^self inflate: self Z_FULL_FLUSH
inflateNoFlush ^self inflate: self Z_NO_FLUSH
inflateSyncFlush ^self inflate: self Z_SYNC_FLUSH
</methods> <methods> OS.ZLib.ZLibInterface <category>inflate-setup teardown</category>
inflateEnd errno := self cInflateEnd: self zstream. errno == self Z_OK ifFalse: [self error: (self errorStringFor: errno)]. ^errno
inflateInit errno := self cInflateInit: self zstream version: self zlibVersion streamSize: self z_stream dataSize. errno ~~ self Z_OK ifTrue: [self error: (self errorStringFor: errno)]. ^errno
</methods> <methods> OS.ZLib.ZLibInterface <category>instance initialization</category>
initializeForEngineAllocator heap := ByteArray newInFixedSpace: HeapSize. zstream := self cOEConflateInitHeapObj: heap
</methods> <methods> OS.ZLib.ZLibInterface class <category>accessing-zlib constants</category>
MAX_WBITS ^15
Z_BEST_COMPRESSION ^9
Z_BEST_SPEED ^1
Z_DEFAULT_COMPRESSION ^-1
Z_DEFLATED ^8
</methods> <methods> OS.ZLib.ZLibInterface class <category>instance creation</category>
newUsingEngineAllocator ^self new initializeForEngineAllocator
</methods> <methods> OS.ZLib.GZipReadStream <category>accessing</category>
checkCrc: aBoolean checkCrc := aBoolean
crc ^crc
</methods> <methods> OS.ZLib.GZipReadStream <category>private</category>
checkCrcAndLength "This class futzing is insanity; see AR46615" | fileCrcAndLength endOfCompressedInput | fileCrcAndLength := UninterpretedBytes new: 8. endOfCompressedInput := interface next_in datum - inputBuffer fixedHeapAddress. inputLimit - endOfCompressedInput >= 8 ifTrue: [ fileCrcAndLength replaceBytesFrom: 1 to: 8 with: inputBuffer startingAt: endOfCompressedInput + 1 ] ifFalse: [ | footerSplit | "This means that some (possibly none) of the footer (crcAndLength) is already in the input buffer and some is still sitting in the sourceStream. We need to figure out what is the split and put the two pieces together. It's also possible to just skip back in the sourceStream based on the split value, but I don't think that imposing positionability on the sourceStream just to make this one bit a little easier is worth it." footerSplit := inputLimit - endOfCompressedInput. "how much of the footer is already in the inputBuffer" fileCrcAndLength replaceBytesFrom: 1 to: footerSplit with: inputBuffer startingAt: endOfCompressedInput + 1. sourceStream next: 8 - footerSplit into: fileCrcAndLength startingAt: footerSplit + 1]. crc ~= (fileCrcAndLength unsignedLongAt: 1 bigEndian: false) ifTrue: [self error: 'file crc error']. interface total_out ~= (fileCrcAndLength unsignedLongAt: 5 bigEndian: false) ifTrue: [self error: 'file length error']
checkHeader | header flags | checkCrc := true. crc := interface cCrc32: 0 buffer: 0 length: 0. header := (sourceStream next: 10) asByteArray. ((header at: 1) ~= (GZipMagic digitAt: 1) or: [(header at: 2) ~= (GZipMagic digitAt: 2) or: [(header at: 3) ~= GZipDeflated]]) ifTrue: [self error: 'input stream is not in gzip format'. ^false]. flags := header at: 4. (flags anyMask: GZipEncryptFlag) ifTrue: [self error:'Cannot decompress encrypted stream'. ^false]. (flags anyMask: GZipReservedFlags) ifTrue: [self error:'Cannot decompress stream with unknown flags'. ^false]. (flags anyMask: GZipContinueFlag) ifTrue: "Number of multi-part archive - ignored" [sourceStream next; next]. (flags anyMask: GZipExtraField) ifTrue: "Extra fields - ignored" [sourceStream next: sourceStream nextWord]. (flags anyMask: GZipNameFlag) ifTrue: "Original file name - ignored" [sourceStream skipThrough: 0]. (flags anyMask: GZipCommentFlag) ifTrue: "Comment - ignored" [sourceStream skipThrough: 0]. ^true
nextBuffer | notAtEnd | notAtEnd := super nextBuffer. checkCrc ifTrue: [readLimit > 0 ifTrue: [crc := interface cCrc32: crc buffer: collection fixedHeapAddress length: readLimit]. notAtEnd ifFalse: [self checkCrcAndLength]]. ^notAtEnd
</methods> <methods> OS.ZLib.ZLibInterface <category>procedures</category>
cAdler32: crc buffer: collection length: length <C: unsigned long adler32(unsigned long crc, unsigned char *collection, unsigned int length)> ^self externalAccessFailedWith: _errorCode
cCrc32: crc buffer: collection length: length <C: unsigned long crc32(unsigned long crc, unsigned char *collection, unsigned int length)> ^self externalAccessFailedWith: _errorCode
cDeflate: zstreampDest copy: zstreampSrc <C: int deflateCopy( z_streamp, z_streamp )> ^self externalAccessFailedWith: _errorCode
cDeflate: zstreamp flush: flushCode <C: int deflate( z_streamp, int )> ^self externalAccessFailedWith: _errorCode
cDeflate: zstreamp setDictionary: dict length: dictLength <C: int deflateSetDictionary( z_streamp, Bytef *, uInt)> ^self externalAccessFailedWith: _errorCode
cDeflateEnd: zstreamp <C: int deflateEnd( z_streamp )> ^self externalAccessFailedWith: _errorCode
cDeflateInit2: zstreamp level: levelCode method: compressionMethod windowBits: log2WindowSize memLevel: amtOfMemToUse strategy: compressionStrategy version: version streamSize: size <C: int deflateInit2_( z_streamp, int, int, int, int, int, char *, int )> ^self externalAccessFailedWith: _errorCode
cDeflateInit: zstreamp level: levelCode version: version streamSize: size <C: int deflateInit_( z_streamp, int, char *, int )> ^self externalAccessFailedWith: _errorCode
cDeflateParams: zstreamp level: levelCode strategy: strategyCode <C: int deflateParams( z_streamp, int, int )> ^self externalAccessFailedWith: _errorCode
cDeflateReset: zstreamp <C: int deflateReset( z_streamp )> ^self externalAccessFailedWith: _errorCode
cInflate: zstreamp flush: flushCode <C: int inflate( z_streamp, int )> ^self externalAccessFailedWith: _errorCode
cInflate: zstreamp setDictionary: dict length: dictLength <C: int inflateSetDictionary( z_streamp, Bytef *, uInt)> ^self externalAccessFailedWith: _errorCode
cInflateEnd: zstreamp <C: int inflateEnd( z_streamp )> ^self externalAccessFailedWith: _errorCode
cInflateInit2: zStream windowBits: windowSize version: versionString streamSize: size <C: int inflateInit2_( z_streamp zStream, int windowSize, char *versionString, int size)> ^self externalAccessFailedWith: _errorCode
cInflateInit: zstreamp version: version streamSize: size <C: int inflateInit_( z_streamp, char *, int )> ^self externalAccessFailedWith: _errorCode
cInflateReset: zstreamp <C: int inflateReset( z_streamp )> ^self externalAccessFailedWith: _errorCode
cInflateSync: zstreamp <C: int inflateSync( z_streamp )> ^self externalAccessFailedWith: _errorCode
cOEConflateInitAlloc: heapBaseAddress length: numBytes <C: z_stream *oeConflateInitAlloc(void *heapBaseAddress, unsigned long numBytes)> ^self externalAccessFailedWith: _errorCode
cOEConflateInitHeapObj: aFixedSpaceObject "Configure a FixedSpace object for use by the oeConflateAlloc/oeConflateFree allocation functions provided by the engine. Answer a suitable z_stream * for passing to deflate, inflate et al. The fixed-space object must be at least of size 32k + 12 + sizeof(z_stream). ZLib itself limits its memory usage to 256K, so the maximum size the buffer need be is 256K + 12 + sizeof(z_stream)" <C: z_stream *oeConflateInitHeapObj(_oop aFixedSpaceObject)> ^self externalAccessFailedWith: _errorCode
cZError: errorCode <C: const char * zError( int errorCode )> ^self externalAccessFailedWith: _errorCode
gzclose: a_gzfile <C: int gzclose( gzFile )> ^self externalAccessFailedWith: _errorCode
gzdopen: fd mode: mode <C: gzFile gzdopen( int, char * )> ^self externalAccessFailedWith: _errorCode
gzeof: a_gzfile <C: int gzeof( gzFile )> ^self externalAccessFailedWith: _errorCode
gzflush: a_gzfile flush: flushCode <C: int gzflush( gzFile, int )> ^self externalAccessFailedWith: _errorCode
gzopen: path mode: mode <C: gzFile gzopen( char * path, char * mode )> ^self externalAccessFailedWith: _errorCode
gzread: a_gzfile buffer: byteObject bufferSize: len <C: int gzread( gzFile, char *, int )> ^self externalAccessFailedWith: _errorCode
gzrewind: a_gzfile <C: int gzrewind( gzFile )> ^self externalAccessFailedWith: _errorCode
gzseek: a_gzfile offset: offset whence: whenceCode <C: int gzseek( gzFile, z_off_t, int )> ^self externalAccessFailedWith: _errorCode
gzsetparams: a_gzfile level: levelCode strategy: strategyCode <C: int gzsetparams( gzFile, int, int )> ^self externalAccessFailedWith: _errorCode
gztell: a_gzfile <C: z_off_t gztell( gzFile )> ^self externalAccessFailedWith: _errorCode
gzwrite: a_gzfile buffer: byteObject bufferSize: len <C: int gzwrite( gzFile, char *, int )> ^self externalAccessFailedWith: _errorCode
zlibVersion <C: char * zlibVersion()> ^self externalAccessFailedWith: _errorCode
</methods> "Imported Classes:" self error: 'Attempting to file-in parcel imports. Choose terminate or close' <class> <name>WriteStream</name> <environment>Core</environment> <super>Core.InternalStream</super> <private>false</private> none <imports></imports> <category>Collections-Streams</category> <attributes> <package>Collections-Streams</package> </attributes> </class> <class> <name>ExternalInterface</name> <environment>External</environment> <super>Core.Object</super> <private>false</private> none includeFiles includeDirectories libraryFiles libraryDirectories virtual optimizationLevel <imports> private Kernel.OpcodePool.* </imports> <category>External-Interface</category> <attributes> <package>External-Interface</package> </attributes> </class> <class> <name>ReadStream</name> <environment>Core</environment> <super>Core.InternalStream</super> <private>false</private> none <imports></imports> <category>Collections-Streams</category> <attributes> <package>Collections-Streams</package> </attributes> </class>