--- a/ZipArchive.st Fri Nov 19 15:54:49 2010 +0100
+++ b/ZipArchive.st Fri Nov 19 16:00:12 2010 +0100
@@ -13,18 +13,10 @@
Object subclass:#ZipArchive
instanceVariableNames:'file mode archiveName firstEntry lastEntry centralDirectory
- startOfArchive endOfArchive'
- classVariableNames:'Lobby RecentlyUsedZipArchives FlushBlock ECREC_SIZE LREC_SIZE
- CREC_SIZE SIZE_CENTRAL_DIRECTORY TOTAL_ENTRIES_CENTRAL_DIR
- C_COMPRESSED_SIZE C_RELATIVE_OFFSET_LOCAL_HEADER
- C_FILENAME_LENGTH C_UNCOMPRESSED_SIZE C_CENTRALHEADERSIGNATURE
- C_LOCALHEADERSIGNATURE C_CENTRALENDSIGNATURE
- ZipFileFormatErrorSignal UnsupportedZipFileFormatErrorSignal
- COMPR_STORED COMPR_SHRUNK COMPR_REDUCED1 COMPR_REDUCED2
- COMPR_REDUCED3 COMPR_REDUCED4 COMPR_IMPLODED COMPR_TOKENIZED
- COMPR_DEFLATED EXTERNALFILEATTRIBUTES_ISFILE
- EXTERNALFILEATTRIBUTES_ISDIRECTORY'
- poolDictionaries:''
+ startOfArchive endOfArchive zipMembersByName'
+ classVariableNames:'Lobby RecentlyUsedZipArchives FlushBlock ZipFileFormatErrorSignal
+ UnsupportedZipFileFormatErrorSignal'
+ poolDictionaries:'ZipArchiveConstants'
category:'System-Support-FileFormats'
!
@@ -55,21 +47,21 @@
externalFileAttributes relativeLocalHeaderOffset fileName
extraField fileComment dataStart data'
classVariableNames:''
- poolDictionaries:''
+ poolDictionaries:'ZipArchiveConstants'
privateIn:ZipArchive
!
ZipArchive::AbstractZipStream subclass:#ZipReadStream
instanceVariableNames:'readPosition peek'
classVariableNames:''
- poolDictionaries:''
+ poolDictionaries:'ZipArchiveConstants'
privateIn:ZipArchive
!
ZipArchive::AbstractZipStream subclass:#ZipWriteStream
instanceVariableNames:''
classVariableNames:''
- poolDictionaries:''
+ poolDictionaries:'ZipArchiveConstants'
privateIn:ZipArchive
!
@@ -1043,7 +1035,8 @@
documentation
"
provides access to a zip archive.
- Caveat: the only compression method (for now) is deflate.
+ Caveat:
+ the only compression methods (for now) are store and deflate.
[author:]
Claus Gittinger
@@ -2941,36 +2934,6 @@
!ZipArchive class methodsFor:'class initialization'!
initialize
- ECREC_SIZE := 18.
- LREC_SIZE := 26.
- CREC_SIZE := 42.
-
- TOTAL_ENTRIES_CENTRAL_DIR := 10.
- SIZE_CENTRAL_DIRECTORY := 12.
-
- C_COMPRESSED_SIZE := 16.
- C_UNCOMPRESSED_SIZE := 20.
- C_FILENAME_LENGTH := 24.
- C_RELATIVE_OFFSET_LOCAL_HEADER := 38.
-
- C_LOCALHEADERSIGNATURE := 16r04034b50.
- C_CENTRALHEADERSIGNATURE := 16r02014b50.
- C_CENTRALENDSIGNATURE := 16r06054b50.
-
- EXTERNALFILEATTRIBUTES_ISFILE := 32.
- EXTERNALFILEATTRIBUTES_ISDIRECTORY := 16.
-
- "/ compression methods
- COMPR_STORED := 0.
- COMPR_SHRUNK := 1.
- COMPR_REDUCED1 := 2.
- COMPR_REDUCED2 := 3.
- COMPR_REDUCED3 := 4.
- COMPR_REDUCED4 := 5.
- COMPR_IMPLODED := 6.
- COMPR_TOKENIZED := 7.
- COMPR_DEFLATED := 8.
-
ZipFileFormatErrorSignal isNil ifTrue:[
ZipFileFormatErrorSignal := OpenError newSignalMayProceed:true.
ZipFileFormatErrorSignal nameClass:self message:#zipFileFormatErrorSignal.
@@ -2989,7 +2952,7 @@
self initialize
"
- "Modified: / 29.3.1998 / 20:17:18 / cg"
+ "Modified: / 19-11-2010 / 15:44:28 / cg"
! !
!ZipArchive class methodsFor:'cleanup'!
@@ -3036,16 +2999,26 @@
!ZipArchive class methodsFor:'constants'!
-COMPR_DEFLATED
+COMPRESSION_DEFLATED
+ <resource: #obsolete>
+
"please use compressionDeflated instead (Squeak compat.)"
- ^ COMPR_DEFLATED
+ self obsoleteMethodWarning.
+ ^ COMPRESSION_DEFLATED
+
+ "Created: / 19-11-2010 / 15:40:38 / cg"
!
-COMPR_STORED
- "please use compressionStored instead (Squeak compat.)"
-
- ^ COMPR_DEFLATED
+COMPR_DEFLATED
+ <resource: #obsolete>
+
+ "please use compressionDeflated instead (Squeak compat.)"
+
+ self obsoleteMethodWarning.
+ ^ COMPRESSION_DEFLATED
+
+ "Modified: / 19-11-2010 / 15:58:28 / cg"
!
LREC_SIZE
@@ -3061,15 +3034,19 @@
!
compressionDeflated
- "same as COMPR_DEFLATED - squeak compatibility"
-
- ^ COMPR_DEFLATED
+ "same as COMPRESSION_DEFLATED - squeak compatibility"
+
+ ^ COMPRESSION_DEFLATED
+
+ "Modified: / 19-11-2010 / 15:58:39 / cg"
!
compressionStored
- "same as COMPR_STORED - squeak compatibility"
-
- ^ COMPR_STORED
+ "same as COMPRESSION_STORED - squeak compatibility"
+
+ ^ COMPRESSION_STORED
+
+ "Modified: / 19-11-2010 / 15:59:00 / cg"
!
streamBufferSize
@@ -3399,14 +3376,14 @@
decode:rawBytes method:compressionMethod size:uncompressedSize
|outBytes|
- compressionMethod == COMPR_STORED ifTrue:[
+ compressionMethod == COMPRESSION_STORED ifTrue:[
"/
"/ uncompressed
"/
^ rawBytes
].
- compressionMethod == COMPR_DEFLATED ifTrue:[
+ compressionMethod == COMPRESSION_DEFLATED ifTrue:[
"/
"/ deflate/inflate algorithm
"/
@@ -3417,31 +3394,31 @@
"/
"/ the other algorithms are not (yet) supported
"/
- compressionMethod == COMPR_SHRUNK ifTrue:[
+ compressionMethod == COMPRESSION_SHRUNK ifTrue:[
self error:'unsupported compression method: SHRUNK'.
^ nil
].
- compressionMethod == COMPR_REDUCED1 ifTrue:[
+ compressionMethod == COMPRESSION_REDUCED1 ifTrue:[
self error:'unsupported compression method: REDUCED1'.
^ nil
].
- compressionMethod == COMPR_REDUCED2 ifTrue:[
+ compressionMethod == COMPRESSION_REDUCED2 ifTrue:[
self error:'unsupported compression method: REDUCED2'.
^ nil
].
- compressionMethod == COMPR_REDUCED3 ifTrue:[
+ compressionMethod == COMPRESSION_REDUCED3 ifTrue:[
self error:'unsupported compression method: REDUCED3'.
^ nil
].
- compressionMethod == COMPR_REDUCED4 ifTrue:[
+ compressionMethod == COMPRESSION_REDUCED4 ifTrue:[
self error:'unsupported compression method: REDUCED4'.
^ nil
].
- compressionMethod == COMPR_IMPLODED ifTrue:[
+ compressionMethod == COMPRESSION_IMPLODED ifTrue:[
self error:'unsupported compression method: IMPLODED'.
^ nil
].
- compressionMethod == COMPR_TOKENIZED ifTrue:[
+ compressionMethod == COMPRESSION_TOKENIZED ifTrue:[
self error:'unsupported compression method: TOKENIZED'.
^ nil
].
@@ -3449,8 +3426,8 @@
self error:'unsupported compression method'.
^ nil
- "Created: / 29.3.1998 / 20:14:45 / cg"
- "Modified: / 8.4.1998 / 10:31:34 / cg"
+ "Created: / 29-03-1998 / 20:14:45 / cg"
+ "Modified: / 19-11-2010 / 15:39:49 / cg"
!
inflate:inBytes to:outBytes
@@ -3499,7 +3476,7 @@
[ zipEntry notNil ] whileTrue: [
noEntries := noEntries + 1.
- file nextPutLong: C_CENTRALHEADERSIGNATURE MSB:false.
+ file nextPutLong: C_CENTRAL_HEADER_SIGNATURE MSB:false.
file nextPutShort:zipEntry versionMadeBy MSB:false.
file nextPutShort:zipEntry versionNeedToExtract MSB:false.
file nextPutShort:zipEntry generalPurposBitFlag MSB:false.
@@ -3546,6 +3523,8 @@
centralDirectory zipCommentLength ~~ 0 ifTrue: [
file nextPutAll: centralDirectory zipComment.
].
+
+ "Modified: / 19-11-2010 / 15:43:15 / cg"
!
addMember
@@ -3602,12 +3581,20 @@
findMember:name
"find a zipMember by name"
+"/ zipMembersByName isNil ifTrue:[
+"/ zipMembersByName := Dictionary new.
+"/ self zipMembersDo:[:zipd |
+"/ zipMembersByName at:(zipd fileName) put:zipd.
+"/ ].
+"/ ].
+"/ ^ zipMembersByName at:name ifAbsent:nil.
+
self zipMembersDo:[:zipd |
(zipd fileName = name) ifTrue:[^ zipd].
].
^ nil
- "Modified: / 30.3.1998 / 17:13:30 / cg"
+ "Modified: / 18-11-2010 / 20:23:35 / cg"
!
readDirectory
@@ -3658,7 +3645,7 @@
^ ZipFileFormatErrorSignal raiseRequestErrorString:' - central directory entry out of archive bounds'.
].
centralFileHeaderSignature := file nextLongMSB:false.
- centralFileHeaderSignature ~= C_CENTRALHEADERSIGNATURE ifTrue:[
+ centralFileHeaderSignature ~= C_CENTRAL_HEADER_SIGNATURE ifTrue:[
ZipFileFormatErrorSignal raiseRequestErrorString:' - file format error - bad centralHeaderSignature in: ' ,
(file isFileStream ifTrue:[file pathName] ifFalse:['inStream']).
^ self.
@@ -3689,7 +3676,7 @@
ZipArchive oldFileNamed:'/usr/lib/jdk1.1.8/lib/classes.zip'
"
- "Modified: / 19.10.1998 / 21:27:32 / cg"
+ "Modified: / 19-11-2010 / 15:43:24 / cg"
!
searchForEndOfCentralDirectorySignature
@@ -3828,14 +3815,14 @@
].
nextBlockSize > 0 ifTrue: [
- zmemb compressionMethod == COMPR_DEFLATED ifTrue:[
+ zmemb compressionMethod == COMPRESSION_DEFLATED ifTrue:[
myZipStream isNil ifTrue: [
file binary.
myZipStream := ZipStream readOpenAsZipStreamOn: file.
].
buffer := myZipStream next:nextBlockSize.
] ifFalse:[
- zmemb compressionMethod == COMPR_STORED ifTrue:[
+ zmemb compressionMethod == COMPRESSION_STORED ifTrue:[
file nextBytes:nextBlockSize into:buffer startingAt:1.
] ifFalse:[
UnsupportedZipFileFormatErrorSignal raiseErrorString:'unsupported compressMethod'
@@ -3853,6 +3840,8 @@
].
^ true.
+
+ "Modified: / 19-11-2010 / 15:58:24 / cg"
!
restoreOsDirectory:osDirectoryName fromArchiveDirectory: archiveDirectoryName
@@ -3994,7 +3983,9 @@
!
addArchiveDirectoryCompressed: archiveDirectoryName fromOsDirectory: osDirectoryName
- ^ self addArchiveDirectory: archiveDirectoryName fromOsDirectory: osDirectoryName compressMethod:COMPR_DEFLATED
+ ^ self addArchiveDirectory: archiveDirectoryName fromOsDirectory: osDirectoryName compressMethod:COMPRESSION_DEFLATED
+
+ "Modified: / 19-11-2010 / 15:58:04 / cg"
!
addDirectory: aDirectoryName
@@ -4002,11 +3993,15 @@
<resource: #obsolete>
- ^ self addFile:aDirectoryName withContents:nil compressMethod:COMPR_STORED asDirectory:true.
+ ^ self addFile:aDirectoryName withContents:nil compressMethod:COMPRESSION_STORED asDirectory:true.
+
+ "Modified: / 19-11-2010 / 15:38:59 / cg"
!
addFile: aFileName fromStream: aStream
- ^ self addFile: aFileName fromStream: aStream compressMethod:COMPR_STORED asDirectory:false
+ ^ self addFile: aFileName fromStream: aStream compressMethod:COMPRESSION_STORED asDirectory:false
+
+ "Modified: / 19-11-2010 / 15:39:02 / cg"
!
addFile:aFileName fromStream:aStream compressMethod: theCompressMethodArg
@@ -4025,11 +4020,11 @@
theCompressMethod := theCompressMethodArg.
- ((theCompressMethod == COMPR_DEFLATED)
- or:[ theCompressMethod == COMPR_STORED ]) ifFalse:[
+ ((theCompressMethod == COMPRESSION_DEFLATED)
+ or:[ theCompressMethod == COMPRESSION_STORED ]) ifFalse:[
UnsupportedZipFileFormatErrorSignal raiseRequestErrorString:'unsupported compressMethod'.
"/ if proceeded, write as uncompressed
- theCompressMethod := COMPR_STORED
+ theCompressMethod := COMPRESSION_STORED
].
zipEntry := ZipMember new default.
@@ -4042,7 +4037,7 @@
zipEntry uncompressedSize: 0.
isDirectory ifTrue: [
- theCompressMethod := COMPR_STORED.
+ theCompressMethod := COMPRESSION_STORED.
zipEntry externalFileAttributes: EXTERNALFILEATTRIBUTES_ISDIRECTORY.
] ifFalse: [
zipEntry compressionMethod: theCompressMethod.
@@ -4074,12 +4069,12 @@
nextBlockSize > 0 ifTrue: [
unCompressedDataSize := unCompressedDataSize + nextBlockSize.
crc32 := ZipStream crc32BytesIn: buffer from:1 to:nextBlockSize crc:crc32.
- theCompressMethod == COMPR_DEFLATED ifTrue: [
+ theCompressMethod == COMPRESSION_DEFLATED ifTrue: [
myZipStream isNil ifTrue: [
myZipStream := ZipStream writeOpenAsZipStreamOn:file.
].
myZipStream nextPutBytes:nextBlockSize from:buffer startingAt:1.
- ] ifFalse: [theCompressMethod == COMPR_STORED ifTrue: [
+ ] ifFalse: [theCompressMethod == COMPRESSION_STORED ifTrue: [
file nextPutBytes:nextBlockSize from:buffer startingAt:1.
] ifFalse:[
UnsupportedZipFileFormatErrorSignal raiseRequestErrorString:'unsupported compressMethod'.
@@ -4100,27 +4095,61 @@
zipEntry rewriteCrcAndSizeTo:file.
file setToEnd.
+
+ "Modified: / 19-11-2010 / 15:39:32 / cg"
!
addFile: aFileName withContents: data
- ^ self addFile: aFileName withContents: data compressMethod:COMPR_STORED asDirectory: false.
+ ^ self addFile: aFileName withContents: data compressMethod:COMPRESSION_STORED asDirectory: false.
+
+ "Modified: / 19-11-2010 / 15:39:13 / cg"
!
addFile:aFileName withContents:data compressMethod:theCompressMethodArg asDirectory:isDirectory
"do not create directories (isDirectory = true) - they are not compatible between operating systems"
+ ^ self basicAddFile:aFileName withContents:data compressMethod:theCompressMethodArg asDirectory:isDirectory
+
+ "Modified: / 18-11-2010 / 19:31:36 / cg"
+!
+
+addFileCompressed: aFileName fromStream: aStream
+ ^ self addFile: aFileName fromStream: aStream compressMethod: COMPRESSION_DEFLATED asDirectory:false
+
+ "Modified: / 19-11-2010 / 15:58:07 / cg"
+!
+
+addFileCompressed: aFileName withContents: data
+ ^ self addFile: aFileName withContents: data compressMethod: COMPRESSION_DEFLATED asDirectory: false.
+
+ "Modified: / 19-11-2010 / 15:58:10 / cg"
+!
+
+addString: aString as: path
+ ^ self
+ addFile: path fromStream: (aString readStream)
+!
+
+basicAddFile:aFileName withContents:data compressMethod:theCompressMethodArg asDirectory:isDirectory
+ "do not create directories (isDirectory = true) - they are not compatible between operating systems"
+
|zipEntry theCompressedData curTime curDate theZipFileName theCompressMethod|
+(aFileName startsWith:'Project') ifFalse:[
+(aFileName startsWith:'Doc') ifFalse:[
+self halt
+].
+].
(file isNil or: [mode ~~ #write]) ifTrue: [
^ self error: 'ZipArchive not open for writing ...'.
].
theCompressMethod := theCompressMethodArg.
- ((theCompressMethod == COMPR_DEFLATED)
- or:[ theCompressMethod == COMPR_STORED ]) ifFalse:[
+ ((theCompressMethod == COMPRESSION_DEFLATED)
+ or:[ theCompressMethod == COMPRESSION_STORED ]) ifFalse:[
UnsupportedZipFileFormatErrorSignal raiseRequestErrorString:'unsupported compressMethod'.
"/ if proceeded, write as uncompressed
- theCompressMethod := COMPR_STORED
+ theCompressMethod := COMPRESSION_STORED
].
zipEntry := ZipMember new default.
@@ -4151,7 +4180,7 @@
zipEntry crc32: (ZipStream crc32BytesIn: data).
].
- (isDirectory not and: [theCompressMethod == COMPR_DEFLATED]) ifTrue: [
+ (isDirectory not and: [theCompressMethod == COMPRESSION_DEFLATED]) ifTrue: [
|tmpCompressedData tmpCompressedDataSize|
tmpCompressedData := ByteArray new:(data size + 16). "/ if the compression is less then the additional overhead we need more space in buffer
tmpCompressedDataSize := ZipStream compress:data into:tmpCompressedData.
@@ -4159,7 +4188,7 @@
zipEntry compressedSize: (tmpCompressedDataSize - 6). "/6 = the zlib specific data 2 bytes in front and 4 bytes behind the real data
theCompressedData := tmpCompressedData copyFrom: 3. "/ 2 bytes before the real data
] ifFalse: [
- theCompressMethod == COMPR_STORED ifTrue:[
+ theCompressMethod == COMPRESSION_STORED ifTrue:[
zipEntry compressedSize: zipEntry uncompressedSize.
theCompressedData := data.
] ifFalse:[
@@ -4175,19 +4204,9 @@
theCompressedData notNil ifTrue: [
file nextPutBytes: zipEntry compressedSize from: theCompressedData.
].
-!
-
-addFileCompressed: aFileName fromStream: aStream
- ^ self addFile: aFileName fromStream: aStream compressMethod: COMPR_DEFLATED asDirectory:false
-!
-
-addFileCompressed: aFileName withContents: data
- ^ self addFile: aFileName withContents: data compressMethod: COMPR_DEFLATED asDirectory: false.
-!
-
-addString: aString as: path
- ^ self
- addFile: path fromStream: (aString readStream)
+
+ "Created: / 18-11-2010 / 19:31:10 / cg"
+ "Modified: / 19-11-2010 / 15:39:26 / cg"
! !
!ZipArchive methodsFor:'writing - stream'!
@@ -4195,7 +4214,9 @@
compressedWriteStreamFor:nameOfFileInArchive
"create new entry in central directory"
- ^ self writeStreamFor:nameOfFileInArchive compressMethod:COMPR_DEFLATED
+ ^ self writeStreamFor:nameOfFileInArchive compressMethod:COMPRESSION_DEFLATED
+
+ "Modified: / 19-11-2010 / 15:58:13 / cg"
!
writeStreamFor:nameOfFileInArchive compressMethod:theCompressMethodArg
@@ -4209,11 +4230,11 @@
theCompressMethod := theCompressMethodArg.
- ((theCompressMethod == COMPR_DEFLATED)
- or:[ theCompressMethod == COMPR_STORED ]) ifFalse:[
+ ((theCompressMethod == COMPRESSION_DEFLATED)
+ or:[ theCompressMethod == COMPRESSION_STORED ]) ifFalse:[
UnsupportedZipFileFormatErrorSignal raiseRequestErrorString:'unsupported compressMethod'.
"/ if proceeded, write as uncompressed
- theCompressMethod := COMPR_STORED
+ theCompressMethod := COMPRESSION_STORED
].
zipEntry := ZipMember new default.
@@ -4242,6 +4263,8 @@
^ (ZipWriteStream zipFileStream:file zipEntry:zipEntry)
zipArchive:self.
+
+ "Modified: / 19-11-2010 / 15:38:54 / cg"
! !
!ZipArchive::AbstractZipStream class methodsFor:'instance creation'!
@@ -4748,7 +4771,7 @@
relativeLocalHeaderOffset := aStream position.
aStream
- nextPutLong:16r04034b50 MSB:false;
+ nextPutLong:C_LOCAL_HEADER_SIGNATURE MSB:false;
nextPutShort:versionNeedToExtract MSB:false;
nextPutShort:generalPurposBitFlag MSB:false;
nextPutShort:compressionMethod MSB:false;
@@ -4762,8 +4785,11 @@
nextPutAll:fileName.
extraField notNil ifTrue: [
+ self assert:(extraField size = extraFieldLength).
aStream nextPutAll:extraField.
].
+
+ "Modified: / 19-11-2010 / 15:45:38 / cg"
! !
!ZipArchive::ZipReadStream methodsFor:'closing'!
@@ -4783,12 +4809,14 @@
uncompressedDataSize := zipEntry uncompressedSize.
readPosition := 0.
- zipEntry compressionMethod == ZipArchive COMPR_DEFLATED ifTrue:[
+ zipEntry compressionMethod == COMPRESSION_DEFLATED ifTrue:[
compressingStream := ZipStream readOpenAsZipStreamOn:zipFileStream.
] ifFalse:[
compressingStream := zipFileStream.
compressingStream text.
].
+
+ "Modified: / 19-11-2010 / 15:47:14 / cg"
! !
!ZipArchive::ZipReadStream methodsFor:'queries'!
@@ -4890,11 +4918,13 @@
crc32 := 0.
uncompressedDataSize := 0.
- zipEntry compressionMethod == ZipArchive COMPR_DEFLATED ifTrue:[
+ zipEntry compressionMethod == COMPRESSION_DEFLATED ifTrue:[
compressingStream := ZipStream writeOpenAsZipStreamOn:zipFileStream.
] ifFalse:[
compressingStream := zipFileStream.
].
+
+ "Modified: / 19-11-2010 / 15:46:57 / cg"
! !
!ZipArchive::ZipWriteStream methodsFor:'queries'!
@@ -4969,11 +4999,11 @@
!ZipArchive class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/ZipArchive.st,v 1.85 2010-09-08 11:06:19 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/ZipArchive.st,v 1.86 2010-11-19 15:00:12 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic2/ZipArchive.st,v 1.85 2010-09-08 11:06:19 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/ZipArchive.st,v 1.86 2010-11-19 15:00:12 cg Exp $'
! !
ZipArchive initialize!