Compression

Archive
This is the abstract superclass for file archives. Archives can be read from or written to files, and contain members that represent files and directories.
addDirectory:
addDirectory:as:
addFile:
addFile:as:
addMember:
addString:as:
addTree:match:
addTree:removingFirstCharacters:
addTree:removingFirstCharacters:match:
canWriteToFileNamed:
Catch attempts to overwrite existing zip file
contentsOf:
extractMember:
extractMember:toFileNamed:
extractMemberWithoutPath:
extractMemberWithoutPath:inDirectory:
initialize
Subclasses should redefine this method to perform initializations on instance creation
member:
memberClass
memberNamed:
Return the first member whose zip name or local file name matches aString, or nil
memberNames
members
membersMatching:
numberOfMembers
removeMember:
replaceMember:with:
setContentsOf:to:
writeTo:
writeToFileNamed:
Catch attempts to overwrite existing zip file
ArchiveMember
This is the abstract superclass for archive members, which are files or directories stored in archives.
close
fileName
fileName:
initialize
Subclasses should redefine this method to perform initializations on instance creation
isCorrupt
isCorrupt:
Mark this member as being corrupt.
localFileName:
Set my internal filename.
Returns the (possibly new) filename.
aString will be translated from local FS format into Unix format.
newDirectoryNamed:
newFromFile:
newFromString:
printOn:
Append to the argument, aStream, a sequence of characters that
identifies the receiver.
usesFileNamed:
Do I require aFileName? That is, do I care if it's clobbered?
CRCError
A CRCError is xxxxxxxxx.
Instance Variables
isResumable
Determine whether an exception is resumable.
DeflateStream
A DeflateStream is xxxxxxxxx.
Instance Variables
blockPosition: <Object>
blockStart: <Object>
hashHead: <Object>
hashTail: <Object>
hashValue: <Object>
blockPosition
- xxxxx
blockStart
- xxxxx
hashHead
- xxxxx
hashTail
- xxxxx
hashValue
- xxxxx
compare:with:min:
Compare the two strings and return the length of matching characters.
minLength is a lower bound for match lengths that will be accepted.
Note: here and matchPos are zero based.
deflateBlock
Deflate the current contents of the stream
deflateBlock:chainLength:goodMatch:
Continue deflating the receiver's collection from blockPosition to lastIndex.
Note that lastIndex must be at least MaxMatch away from the end of collection
encodeLiteral:
Encode the given literal.
Return true if the current block needs to be flushed.
encodeMatch:distance:
Encode a match of the given length and distance.
Return true if the current block should be flushed.
findMatch:lastLength:lastMatch:chainLength:goodMatch:
Find the longest match for the string starting at here.
If there is no match longer than lastLength return lastMatch/lastLength.
Traverse at most maxChainLength entries in the hash table.
Stop if a match of at least goodMatch size has been found.
flush
Force compression
flushBlock
Flush a deflated block
goodMatchLength
Return the length that is considered to be a 'good' match.
Higher values will result in better compression but take more time.
hashChainLength
Return the max. number of hash chains to traverse.
Higher values will result in better compression but take more time.
initialize
Subclasses should redefine this method to perform initializations on instance creation
initializeHashTables
insertStringAt:
Insert the string at the given start position into the hash table.
Note: The hash value is updated starting at MinMatch-1 since
all strings before have already been inserted into the hash table
(and the hash value is updated as well).
moveContentsToFront
Move the contents of the receiver to the front
next:putAll:startingAt:
Store the next anInteger elements from the given collection.
nextPutAll:
Append the elements of aCollection to the sequence of objects accessible
by the receiver. Answer aCollection.
on:
on:from:to:
Not for DeflateStreams please
pastEndPut:
Grow the collection by doubling the size, but keeping the growth between 20 and 1000000.
Then put <anObject> at the current write position.
updateHash:
Update the running hash value based on the next input byte.
Return the new updated hash value.
updateHashAt:
Update the hash value at position here (one based)
updateHashTable:delta:
validateMatchAt:from:to:
FastInflateStream
This class adds the following optimizations to the basic Inflate decompression:
a) Bit reversed access
If we want to fetch the bits efficiently then we have them in the wrong bit order (e.g., when we should fetch 2r100 we would get 2r001). But since the huffman tree lookup determines the efficiency of the decompression, reversing the bits before traversal is expensive. Therefore the entries in each table are stored in REVERSE BIT ORDER. This is achieved by a reverse increment of the current table index in the huffman table construction phase (see method increment:bits:). According to my measures this speeds up the implementation by about 30-40%.
b) Inplace storage of code meanings and extra bits
Rather than looking up the meaning for each code during decompression of blocks we store the appropriate values directly in the huffman tables, using a pre-defined mapping. Even though this does not make a big difference in speed, it cleans up the code and allows easier translation into primitive code (which is clearly one goal of this implementation).
c) Precomputed huffman tables for fixed blocks
So we don't have to compute the huffman tables from scratch. The precomputed tables are not in our superclass to avoid double storage (and my superclass is more intended for documentation anyways).
decompressBlock:with:
Process the compressed data in the block.
llTable is the huffman table for literal/length codes
and dTable is the huffman table for distance codes.
distanceMap
This is used by the fast decompressor
increment:bits:
Increment value in reverse bit order, e.g.
for a 3 bit value count as follows:
000 / 100 / 010 / 110
001 / 101 / 011 / 111
See the class comment why we need this.
initialize
Subclasses should redefine this method to perform initializations on instance creation
literalLengthMap
This is used by the fast decompressor
nextSingleBits:
Fetch the bits all at once
processFixedBlock
GZipConstants
A GZipConstants is xxxxxxxxx.
Instance Variables
gzipMagic
initialize
Subclasses should redefine this method to perform initializations on instance creation
GZipReadStream
A GZipReadStream is xxxxxxxxx.
Instance Variables
fileIn:
fileIntoNewChangeSet:
fileReaderServicesForFile:suffix:
on:from:to:
Check the header of the GZIP stream.
saveContents:
serviceDecompressToFile
serviceFileIn
serviceFileIntoNewChangeSet
serviceViewDecompress
services
uncompressedFileName:
unload
updateCrc:from:to:in:
Answer an updated CRC for the range of bytes in aCollection
verifyCrc
Verify the crc checksum in the input
viewContents:
GZipSurrogateStream
A pseudo stream that allows SmartRefStream to write directly to a gzipped file. There are some peculiarities of the project exporting process that require:
1. We ignore #close since the file is closed and may be reopened to continue writing. We implement #reallyClose for when we know that all writing is over.
2. We use a BitBlt to write WordArrayForSegment objects. Bit of a hack, but there it is.
| fileStream wa |
wa _ WordArrayForSegment new: 30000.
1 to: wa size do: [ :i | wa at: i put: i].
fileStream _ GZipSurrogateStream newFileNamed: 'xxx3.gz' inDirectory: FileDirectory default.
fileStream nextPutAll: 'this is a test'.
fileStream nextPutAll: wa.
fileStream reallyClose.
ascii
binary
bufferStream
close
we don't want to until user is really done
closed
command:
Overridden by HtmlFileStream to append commands directly without translation. 4/5/96 tk
cr
fileOutClass:andObject:
Write a file that has both the source code for the named class and an object as bits. Any instance-specific object will get its class written automatically.
flushBuffer
header
ignore
newFileNamed:inDirectory:
next
nextChunkPut:
nextInt32Put:
nextNumber:put:
nextPut:
nextPutAll:
nextPutAllBytes:
nextPutAllWordArray:
nextStringPut:
Append the string, s, to the receiver. Only used by DataStream. Max size of 64*256*256*256.
nextWordsPutAll:
Write the argument a word-like object in big endian format on the receiver.
May be used to write other than plain word-like objects (such as ColorArray).
originalContents
padToEndWith:
We don't have pages, so we are at the end, and don't need to pad.
position
reallyClose
reopen
ignore
setFileTypeToObject
ignore
setToEnd
ignore
skip:
timeStamp
Append the current time to the receiver as a String.
trailer
ignore
GZipWriteStream
A GZipWriteStream is xxxxxxxxx.
Instance Variables
compressFile:
fileReaderServicesForFile:suffix:
initialize
Subclasses should redefine this method to perform initializations on instance creation
serviceCompressFile
services
unload
writeFooter
Write some footer information for the crc
writeHeader
Write the GZip header
InflateStream
This class implements the Inflate decompression algorithm as defined by RFC1951 and used in PKZip, GZip and ZLib (and many, many more). It is a variant of the LZ77 compression algorithm described in
[LZ77] Ziv J., Lempel A., "A Universal Algorithm for Sequential Data Compression", IEEE Transactions on Information Theory", Vol. 23, No. 3, pp. 337-343.
[RFC1951] Deutsch. P, "DEFLATE Compressed Data Format Specification version 1.3"
For more information see the above mentioned RFC 1951 which can for instance be found at
http://www.leo.org/pub/comp/doc/standards/rfc/index.html
Huffman Tree Implementation Notes:
===========================================
The huffman tree used for decoding literal, distance and length codes in the inflate algorithm has been encoded in a single Array. The tree is made up of subsequent tables storing all entries at the current bit depth. Each entry in the table (e.g., a 32bit Integer value) is either a leaf or a non-leaf node. Leaf nodes store the immediate value in its low 16 bits whereas non-leaf nodes store the offset of the subtable in its low 16bits. The high 8 bits of non-leaf nodes contain the number of additional bits needed for the sub table (the high 8 bits of leaf-nodes are always zero). The first entry in each table is always a non-leaf node indicating how many bits we need to fetch initially. We can thus travel down the tree as follows (written in sort-of-pseudocode the actual implementation can be seen in InflateStream>>decodeValueFrom:):
table _ initialTable.
bitsNeeded _ high 8 bits of (table at: 1). "Determine initial bits"
table _ initialTable + (low 16 bits of (table at: 1)). "Determine start of first real table"
[bits _ fetch next bitsNeeded bits. "Grab the bits"
value _ table at: bits. "Lookup the value"
value has high 8 bit set] whileTrue:[ "Check if it's leaf"
table _ initialTable + (low 16 bits of value). "No - compute new sub table start"
bitsNeeded _ high 8 bit of value]. "Compute additional number of bits needed"
^value
atEnd
Note: It is possible that we have a few bits left,
representing just the EOB marker. To check for
this we must force decompression of the next
block if at end of data.
bitPosition
Return the current bit position of the source
close
Presumably sets the status of the receiver to be closed. This message does
nothing at this level, but is included for FileStream compatibility.
computeHuffmanValues:counts:from:to:
Assign numerical values to all codes.
Note: The values are stored according to the bit length
contents
Answer with a copy of my collection from 1 to readLimit.
crcError:
createHuffmanTables:counts:from:to:
Create the actual tables
decodeDynamicTable:from:
Decode the code length of the literal/length and distance table
in a block compressed with dynamic huffman trees
decodeValueFrom:
Decode the next value in the receiver using the given huffman table.
decompressAll
Profile the decompression speed
decompressBlock:with:
Process the compressed data in the block.
llTable is the huffman table for literal/length codes
and dTable is the huffman table for distance codes.
distanceMap
This is used by the fast decompressor
getFirstBuffer
Get the first source buffer after initialization has been done
getNextBlock
growHuffmanTable:
huffmanTableFrom:mappedBy:
Create a new huffman table from the given code lengths.
Map the actual values by valueMap if it is given.
See the class comment for a documentation of the huffman
tables used in this decompressor.
increment:bits:
Increment a value of nBits length.
The fast decompressor will do this differently
initialize
Subclasses should redefine this method to perform initializations on instance creation
literalLengthMap
This is used by the fast decompressor
mapValues:by:
moveContentsToFront
Move the decoded contents of the receiver to the front so that we have enough space for decoding more data.
moveSourceToFront
Move the encoded contents of the receiver to the front so that we have enough space for decoding more data.
next
Answer the next decompressed object in the Stream represented by the
receiver.
next:
Answer the next anInteger elements of my collection. overriden for simplicity
next:into:startingAt:
Read n objects into the given collection.
Return aCollection or a partial copy if less than
n elements have been read.
nextBits:
nextByte
nextSingleBits:
on:
on:from:to:
pastEndRead
A client has attempted to read beyond the read limit.
Check in what state we currently are and perform
the appropriate action
proceedDynamicBlock
proceedFixedBlock
proceedStoredBlock
Proceed decompressing a stored (e.g., uncompressed) block
processDynamicBlock
processFixedBlock
processStoredBlock
Skip to byte boundary
profile
Profile the decompression speed
reset
Position zero - nothing decoded yet
size
This is a compressed stream - we don't know the size beforehand
sourceLimit
sourcePosition
sourceStream
upTo:
Answer a subcollection from the current access position to the
occurrence (if any, but not inclusive) of anObject in the receiver. If
anObject is not in the collection, answer the entire rest of the receiver.
upToEnd
Answer a subcollection from the current access position through the last element of the receiver.
updateCrc:from:to:in:
Answer an updated CRC for the range of bytes in aCollection.
Subclasses can implement the appropriate means for the check sum they wish to use.
verifyCrc
Verify the crc checksum in the input
TarArchive
This is a kind of archive that uses the TAR format (popular in Unix). It is here as a placeholder.
memberClass
TarArchiveMember
A TarArchiveMember is xxxxxxxxx.
Instance Variables
ZLibReadStream
A ZLibReadStream is xxxxxxxxx.
Instance Variables
on:from:to:
Check the header of the ZLib stream.
updateCrc:from:to:in:
Answer an updated CRC for the range of bytes in aCollection
verifyCrc
Verify the crc checksum in the input
ZLibWriteStream
A ZLibWriteStream is xxxxxxxxx.
Instance Variables
on:
updateAdler32:from:to:in:
updateCrc:from:to:in:
Update crc using the Adler32 checksum technique from RFC1950
writeFooter
Store the Adler32 checksum as the last 4 bytes.
writeHeader
Write header information
ZipArchive
A ZipArchive represents an archive that is read and/or written using the PKZIP file format.
ZipArchive instances know how to read and write such archives; their members are subinstances of ZipArchiveMember.
addDeflateString:as:
Add a verbatim string under the given file name
close
compressionDeflated
compressionLevelDefault
compressionLevelNone
compressionStored
extractAllTo:
Extract all elements to the given directory
extractAllTo:informing:
Extract all elements to the given directory
extractAllTo:informing:overwrite:
Extract all elements to the given directory
findEndOfCentralDirectoryFrom:
hasMemberSuchThat:
Answer whether we have a member satisfying the given condition
initialize
Subclasses should redefine this method to perform initializations on instance creation
isZipArchive:
memberClass
prependedDataSize
Answer the size of whatever data exists before my first member.
Assumes that I was read from a file or stream (i.e. the first member is a ZipFileMember)
readEndOfCentralDirectoryFrom:
Read EOCD, starting from position before signature.
readFrom:
readMembersFrom:named:
readSignatureFrom:
Returns next signature from given stream, leaves stream positioned afterwards.
validSignatures
writeCentralDirectoryTo:
writeEndOfCentralDirectoryTo:
writeTo:
writeTo:prepending:
writeTo:prependingFileNamed:
writeToFileNamed:prepending:
Catch attempts to overwrite existing zip file
writeToFileNamed:prependingFileNamed:
Catch attempts to overwrite existing zip file
zipFileComment
zipFileComment:
ZipArchiveMember
Subinstances of me are members in a ZipArchive.
They represent different data sources:
* ZipDirectoryMember -- a directory to be added to a zip file
* ZipFileMember -- a file or directory that is already in a zip file
* ZipNewFilemember -- a file that is to be added to a zip file
* ZipStringMember -- a string that is to be added to a zip file
They can write their data to another stream either copying, compressing,
or decompressing as desired.
asDirectory
centralDirectoryHeaderSize
clearExtraFields
compressDataTo:
Copy my deflated data to the given stream.
compressedSize
Return the compressed size for this member.
This will not be set for members that were constructed from strings
or external files until after the member has been written.
compressionMethod
Returns my compression method. This is the method that is
currently being used to compress my data.
This will be CompressionStored for added string or file members,
or CompressionStored or CompressionDeflated (others are possible but not handled)
contentStream
Answer my contents as a text stream.
Default is no conversion, since we don't know what the bytes mean.
contents
Answer my contents as a string.
contentsFrom:to:
Answer my contents as a string.
copyDataTo:
copyDataWithCRCTo:
Copy my data to aStream. Also set the CRC-32.
Only used when compressionMethod = desiredCompressionMethod = CompressionStored
copyRawDataTo:
copyRawDataTo:from:to:
crc32
crc32String
desiredCompressionLevel
desiredCompressionLevel:
Set my desiredCompressionLevel
This is the method that will be used to write.
Returns prior desiredCompressionLevel.
Valid arguments are 0 (CompressionLevelNone) through 9,
including 6 (CompressionLevelDefault).
0 (CompressionLevelNone) will change the desiredCompressionMethod
to CompressionStored. All other arguments will change the
desiredCompressionMethod to CompressionDeflated.
desiredCompressionMethod
Get my desiredCompressionMethod.
This is the method that will be used to write
desiredCompressionMethod:
Set my desiredCompressionMethod
This is the method that will be used to write.
Answers prior desiredCompressionMethod.
Only CompressionDeflated or CompressionStored are valid arguments.
Changing to CompressionStored will change my desiredCompressionLevel
to CompressionLevelNone; changing to CompressionDeflated will change my
desiredCompressionLevel to CompressionLevelDefault.
dosToUnixTime:
DOS years start at 1980, Unix at 1970, and Smalltalk at 1901.
So the Smalltalk seconds will be high by 69 years when used as Unix time:=t values.
So shift 1980 back to 1911...
endRead
extractInDirectory:
extractInDirectory:overwrite:
Extract this entry into the given directory. Answer #okay, #failed, #abort, or #retryWithOverwrite.
extractTo:
extractTo:from:to:
extractToFileNamed:
extractToFileNamed:inDirectory:
fileComment
fileComment:
hasDataDescriptor
initialize
Subclasses should redefine this method to perform initializations on instance creation
isDirectory
isEncrypted
Return true if this member is encrypted (this is unsupported)
isTextFile
Returns true if I am a text file.
Note that this module does not currently do anything with this flag
upon extraction or storage.
That is, bytes are stored in native format whether or not they came
from a text file.
isTextFile:
Set whether I am a text file.
Note that this module does not currently do anything with this flag
upon extraction or storage.
That is, bytes are stored in native format whether or not they came
from a text file.
lastModTime
Return my last modification date/time stamp,
converted to Squeak seconds
localFileName
Answer my fileName in terms of the local directory naming convention
looksLikeDirectory
mapPermissionsFromUnix:
mapPermissionsToUnix:
newFromDirectory:
newFromFile:
newFromString:named:
newFromZipFile:named:
readRawChunk:
refreshLocalFileHeaderTo:
Re-writes my local header to the given stream.
To be called after writing the data stream.
Assumes that fileName and localExtraField sizes didn't change since last written.
rewindData
setLastModFileDateTimeFrom:
splitFileName
Answer my name split on slash boundaries. A directory will have a trailing empty string.
uncompressedSize
Return the uncompressed size for this member.
unixFileAttributes
unixFileAttributes:
unixToDosTime:
unixToSqueakTime:
writeCentralDirectoryFileHeaderTo:
C2 v3 V4 v5 V2
writeDataDescriptorTo:
This writes a data descriptor to the given stream.
Assumes that crc32, writeOffset, and uncompressedSize are
set correctly (they should be after a write).
Further, the local file header should have the
GPBF:=HAS:=DATA:=DESCRIPTOR:=MASK (8) bit set.
writeDataTo:
Copy my (possibly inflated or deflated) data to the given stream.
This might do compression, decompression, or straight copying, depending
on the values of compressionMethod and desiredCompressionMethod
writeDataTo:from:to:
Copy my (possibly inflated or deflated) data to the given stream.
But only the specified byte range.
This might do decompression, or straight copying, depending
on the values of compressionMethod and desiredCompressionMethod
writeLocalFileHeaderTo:
Write my local header to a file handle.
Stores the offset to the start of the header in my
writeLocalHeaderRelativeOffset member.
writeTo:
ZipConstants
A ZipConstants is xxxxxxxxx.
Instance Variables
initialize
Subclasses should redefine this method to perform initializations on instance creation
initializeDeflateConstants
initializeDistanceCodes
initializeExtraBits
initializeFixedTrees
initializeLengthCodes
initializeWriteStreamConstants
ZipDirectoryMember
ZipFileMember instances represent directories inside ZipArchives.
They don't do much other than hold names and permissions (and extra fields).
You can add files in subdirectories to a ZipArchive without using any ZipDirectoryMembers.
asDirectory
desiredCompressionMethod:
Set my desiredCompressionMethod
This is the method that will be used to write.
Answers prior desiredCompressionMethod.
Only CompressionDeflated or CompressionStored are valid arguments.
Changing to CompressionStored will change my desiredCompressionLevel
to CompressionLevelNone; changing to CompressionDeflated will change my
desiredCompressionLevel to CompressionLevelDefault.
initialize
Subclasses should redefine this method to perform initializations on instance creation
isDirectory
localFileName:
Set my internal filename.
Returns the (possibly new) filename.
aString will be translated from local FS format into Unix format.
newNamed:
rewindData
usesFileNamed:
Do I require aFileName? That is, do I care if it's clobbered?
ZipEncoder
A ZipEncoder is xxxxxxxxx.
Instance Variables
bitBuffer: <Object>
bitPosition: <Object>
encodedStream: <Object>
bitBuffer
- xxxxx
bitPosition
- xxxxx
encodedStream
- xxxxx
bitPosition
close
Presumably sets the status of the receiver to be closed. This message does
nothing at this level, but is included for FileStream compatibility.
commit
encodedStream
flush
Do nothing by default
flushBits
Flush currently unsent bits
nextBits:put:
Store a value of nBits
nextBytePut:
Primitive. Insert the argument at the next position in the Stream
represented by the receiver. Fail if the collection of this stream is not an
Array or a String. Fail if the stream is positioned at its end, or if the
position is out of bounds in the collection. Fail if the argument is not
of the right type for the collection. Optional. See Object documentation
whatIsAPrimitive.
on:
pastEndPut:
Flush the current buffer and store the new object at the beginning
privateSendBlock:with:with:with:
Send the current block using the encodings from the given literal/length and distance tree
sendBlock:with:with:with:
Send the current block using the encodings from the given literal/length and distance tree
ZipEncoderNode
ZipEncoderNode represents a node in a huffman tree for encoding ZipStreams.
Instance variables:
value <Integer> - Encoded value
frequency <Integer> - Number of occurences of the encoded value
height <Integer> - Height of the node in the tree
bitLength <Integer> - bit length of the code
code <Integer> - Assigned code for this node
parent <ZipEncoderNode> - Parent of this node
left <ZipEncoderNode> - First child of this node
right <ZipEncoderNode> - Second child of this node
bitLength
code
code:
computeHeight
encodeBitLength:from:
Note: If bitLength is not nil then the tree must be broken
frequency
frequency:
height
isLeaf
leafNodes
left
left:
parent
parent:
printOn:
Append to the argument, aStream, a sequence of characters that
identifies the receiver.
right
right:
rotateToHeight:
Rotate the tree to achieve maxHeight depth
setBitLengthTo:
setValue:frequency:height:
value
value:frequency:height:
ZipEncoderTree
ZipEncoderTree represents a huffman tree for encoding ZipStreams.
Instance variables:
bitLengths <WordArray> - Bit lengths of each generated code
codes <WordArray> - Codes for each value
maxCode <Integer> - Maximum value with non-zero frequency
bitLengthAt:
bitLengths
Return an array of all bitLength values for valid codes
bitLengths:codes:
buildCodes:counts:maxDepth:
Build the codes for all nodes
buildHierarchyFrom:
Build the node hierarchy based on the leafs in aHeap
buildTree:maxDepth:
Build either the literal or the distance tree
buildTreeFrom:maxDepth:
Build the receiver from the given frequency values
codeAt:
codes
Return an array of all valid codes
maxCode
maxCode:
nodeSortBlock
reverseBits:length:
Bit reverse the given code
setValuesFrom:
ZipFileConstants
A ZipFileConstants is xxxxxxxxx.
Instance Variables
initialize
Subclasses should redefine this method to perform initializations on instance creation
ZipFileMember
ZipNewFileMember instances are used to represent files that have been read from a ZipArchive.
Their data stays in the file on disk, so the original Zip file cannot be directly overwritten.
canonicalizeFileName
For security reasons, make all paths relative and remove any ../ portions
close
copyDataTo:
initialize
Subclasses should redefine this method to perform initializations on instance creation
localHeaderRelativeOffset
looksLikeDirectory
newFrom:named:
readCentralDirectoryFileHeaderFrom:
Assumes aStream positioned after signature
readFrom:
assumes aStream positioned after CD header; leaves stream positioned after my CD entry
readLocalDirectoryFileHeaderFrom:
Positions stream as necessary. Will return stream to its original position
readRawChunk:
rewindData
skipLocalDirectoryFileHeaderFrom:
Assumes that stream is positioned after signature.
stream:externalFileName:
uncompressDataTo:
uncompressDataTo:from:to:
usesFileNamed:
Do I require aFileName? That is, do I care if it's clobbered?
ZipNewFileMember
ZipNewFileMember instances are used to represent files that are going to be written to a ZipArchive.
Their data comes from external file streams.
close
from:
initialize
Subclasses should redefine this method to perform initializations on instance creation
newNamed:
readRawChunk:
rewindData
usesFileNamed:
Do I require aFileName? That is, do I care if it's clobbered?
ZipReadStream
ZipReadStream is intended for uncompressing the compressed contents of Zip archive members.
Since Zip archive members keep their expected CRC value separately in Zip headers, this class does not attempt to read the CRC from its input stream.
Instead, if you want the CRC verification to work you have to call #expectedCrc: with the expected CRC-32 value from the Zip member header.
expectedCrc:
If expectedCrc is set, it will be compared against the calculated CRC32 in verifyCrc.
This number should be the number read from the Zip header (which is the bitwise complement of my crc if all is working correctly)
on:from:to:
updateCrc:from:to:in:
Answer an updated CRC for the range of bytes in aCollection.
Subclasses can implement the appropriate means for the check sum they wish to use.
verifyCrc
Verify the CRC-32 checksum calculated from the input against the expected CRC-32, if any.
Answer the calculated CRC-32 in any case.
Note that the CRC-32 used in Zip files is actually the bit inverse of the calculated value, so that is what is returned.
ZipStringMember
ZipStringMember instances are used to represent files that are going to be written to a ZipArchive.
Their data comes from in-image strings, though.
contents
Answer my contents as a string.
contents:
initialize
Subclasses should redefine this method to perform initializations on instance creation
newFrom:named:
readRawChunk:
rewindData
ZipWriteStream
A ZipWriteStream is xxxxxxxxx.
Instance Variables
bytesWritten: <Object>
crc: <Object>
crcPosition: <Object>
distanceFreq: <Object>
distances: <Object>
encoder: <Object>
litCount: <Object>
literalFreq: <Object>
literals: <Object>
matchCount: <Object>
bytesWritten
- xxxxx
crc
- xxxxx
crcPosition
- xxxxx
distanceFreq
- xxxxx
distances
- xxxxx
encoder
- xxxxx
litCount
- xxxxx
literalFreq
- xxxxx
literals
- xxxxx
matchCount
- xxxxx
baseDistance
baseLength
close
Presumably sets the status of the receiver to be closed. This message does
nothing at this level, but is included for FileStream compatibility.
compressAndDecompress:using:stats:
crc
crcTable
deflateBlock:chainLength:goodMatch:
^DeflatePlugin doPrimitive:#primitiveDeflateBlock
distanceCodes
dynamicBlockSizeFor:and:using:and:
Compute the length for the current block using dynamic huffman trees
encodeLiteral:
Encode the given literal
encodeMatch:distance:
Encode the given match of length length starting at dist bytes ahead
encodedStream
extraDistanceBits
extraLengthBits
finish
Finish pending operation. Do not close output stream.
fixedBlockSizeFor:and:
Compute the length for the current block using fixed huffman trees
flushBlock
Flush a deflated block
flushBlock:
Send the current block
forcedMethod
Return a symbol describing an enforced method or nil if the method should
be chosen adaptively. Valid symbols are
#stored - store blocks (do not compress)
#fixed - use fixed huffman trees
#dynamic - use dynamic huffman trees.
initialize
Subclasses should redefine this method to perform initializations on instance creation
initializeCrcTable
initializeNewBlock
Initialize the encoder for a new block of data
logProblem:for:
matchLengthCodes
maxDistanceCodes
maxLiteralCodes
moveContentsToFront
Need to update crc here
on:
printRegressionStats:from:
regressionCompress:into:notifiying:stats:
regressionDecompress:from:notifying:stats:
regressionTest
regressionTestFrom:
regressionTestFrom:using:stats:
release
We're done with compression. Do some cleanup.
scanBitLength:repeatCount:into:
Update the frequency for the aTree based on the given values
scanBitLengths:into:
Scan the trees and determine the frequency of the bit lengths.
For repeating codes, emit a repeat count.
sendBitLength:repeatCount:tree:
Send the given bitLength, repeating repeatCount times
sendBitLength:tree:
Send the given bitLength
sendBitLengthTree:
Send the bit length tree
sendCompressedBlock:with:
Send the current block using the encodings from the given literal/length and distance tree
sendDynamicBlock:literalTree:distanceTree:bitLengths:
Send a block using dynamic huffman trees
sendFixedBlock
Send a block using fixed huffman trees
sendLiteralTree:distanceTree:using:bitLengths:
Send all the trees needed for dynamic huffman tree encoding
sendStoredBlock
Send an uncompressed block
shouldFlush
Check if we should flush the current block.
Flushing can be useful if the input characteristics change.
storedBlockSize
Compute the length for the current block when stored as is
updateCrc
updateCrc:from:to:in:
writeFooter
Write footer information if necessary
writeHeader
Write header information if necessary