--- a/ZipArchive.st Mon Nov 19 12:33:42 2018 +0100
+++ b/ZipArchive.st Thu Nov 22 15:45:29 2018 +0100
@@ -3732,7 +3732,7 @@
|noEntries|
centralDirectory isNil ifTrue: [
- centralDirectory := ZipCentralDirectory new default.
+ centralDirectory := ZipCentralDirectory new default.
].
noEntries := 0.
@@ -3743,36 +3743,36 @@
centralDirectory centralDirectoryStartOffset: stream position.
self zipMembersDo:[:zipEntry |
- noEntries := noEntries + 1.
- stream nextPutInt32LSB: C_CENTRAL_HEADER_SIGNATURE.
- stream nextPutInt16LSB:zipEntry versionMadeBy.
- stream nextPutInt16LSB:zipEntry versionNeedToExtract.
- stream nextPutInt16LSB:zipEntry generalPurposBitFlag.
- stream nextPutInt16LSB:zipEntry compressionMethod.
- stream nextPutInt16LSB:zipEntry lastModFileTime.
- stream nextPutInt16LSB:zipEntry lastModFileDate.
- stream nextPutInt32LSB:zipEntry crc32.
- stream nextPutInt32LSB:zipEntry compressedSize.
- stream nextPutInt32LSB:zipEntry uncompressedSize.
- stream nextPutInt16LSB:zipEntry fileNameLength.
- stream nextPutInt16LSB:zipEntry extraFieldLength.
- stream nextPutInt16LSB:zipEntry fileCommentLength.
- stream nextPutInt16LSB:zipEntry diskNumberStart.
- stream nextPutInt16LSB:zipEntry internalFileAttributes.
- stream nextPutInt32LSB:zipEntry externalFileAttributes.
- stream nextPutInt32LSB:zipEntry relativeLocalHeaderOffset.
-
- self assert:zipEntry fileNameLength = zipEntry fileName size.
- stream nextPutAll:zipEntry fileName.
-
- zipEntry extraField notNil ifTrue: [
- self assert:zipEntry extraFieldLength = zipEntry extraField size.
- stream nextPutAll:zipEntry extraField.
- ].
- zipEntry fileComment notNil ifTrue: [
- self assert:zipEntry fileCommentLength = zipEntry fileComment size.
- stream nextPutAll:zipEntry fileComment.
- ].
+ noEntries := noEntries + 1.
+ stream nextPutInt32:C_CENTRAL_HEADER_SIGNATURE MSB:false.
+ stream nextPutInt16:zipEntry versionMadeBy MSB:false.
+ stream nextPutInt16:zipEntry versionNeedToExtract MSB:false.
+ stream nextPutInt16:zipEntry generalPurposBitFlag MSB:false.
+ stream nextPutInt16:zipEntry compressionMethod MSB:false.
+ stream nextPutInt16:zipEntry lastModFileTime MSB:false.
+ stream nextPutInt16:zipEntry lastModFileDate MSB:false.
+ stream nextPutInt32:zipEntry crc32 MSB:false.
+ stream nextPutInt32:zipEntry compressedSize MSB:false.
+ stream nextPutInt32:zipEntry uncompressedSize MSB:false.
+ stream nextPutInt16:zipEntry fileNameLength MSB:false.
+ stream nextPutInt16:zipEntry extraFieldLength MSB:false.
+ stream nextPutInt16:zipEntry fileCommentLength MSB:false.
+ stream nextPutInt16:zipEntry diskNumberStart MSB:false.
+ stream nextPutInt16:zipEntry internalFileAttributes MSB:false.
+ stream nextPutInt32:zipEntry externalFileAttributes MSB:false.
+ stream nextPutInt32:zipEntry relativeLocalHeaderOffset MSB:false.
+
+ self assert:zipEntry fileNameLength = zipEntry fileName size.
+ stream nextPutAll:zipEntry fileName.
+
+ zipEntry extraField notNil ifTrue: [
+ self assert:zipEntry extraFieldLength = zipEntry extraField size.
+ stream nextPutAll:zipEntry extraField.
+ ].
+ zipEntry fileComment notNil ifTrue: [
+ self assert:zipEntry fileCommentLength = zipEntry fileComment size.
+ stream nextPutAll:zipEntry fileComment.
+ ].
].
centralDirectory centralDirectoryTotalNoOfEntries: noEntries.
@@ -3783,19 +3783,20 @@
stream nextPutByte:($K codePoint).
stream nextPutByte:8r005.
stream nextPutByte:8r006.
- stream nextPutInt16LSB:centralDirectory numberOfThisDisk.
- stream nextPutInt16LSB:centralDirectory centralDirectoryStartDiskNumber.
- stream nextPutInt16LSB:centralDirectory centralDirectoryTotalNoOfEntriesOnThisDisk.
- stream nextPutInt16LSB:centralDirectory centralDirectoryTotalNoOfEntries.
- stream nextPutInt32LSB:centralDirectory centralDirectorySize.
- stream nextPutInt32LSB:centralDirectory centralDirectoryStartOffset.
- stream nextPutInt16LSB:centralDirectory zipCommentLength.
+ stream nextPutInt16:centralDirectory numberOfThisDisk MSB:false.
+ stream nextPutInt16:centralDirectory centralDirectoryStartDiskNumber MSB:false.
+ stream nextPutInt16:centralDirectory centralDirectoryTotalNoOfEntriesOnThisDisk MSB:false.
+ stream nextPutInt16:centralDirectory centralDirectoryTotalNoOfEntries MSB:false.
+ stream nextPutInt32:centralDirectory centralDirectorySize MSB:false.
+ stream nextPutInt32:centralDirectory centralDirectoryStartOffset MSB:false.
+ stream nextPutInt16:centralDirectory zipCommentLength MSB:false.
centralDirectory zipCommentLength ~~ 0 ifTrue: [
- stream nextPutAll: centralDirectory zipComment.
+ stream nextPutAll: centralDirectory zipComment.
].
"Modified: / 19-11-2010 / 16:23:36 / cg"
+ "Modified: / 22-11-2018 / 15:36:07 / Stefan Vogel"
!
addMember:zmemb
@@ -4279,7 +4280,9 @@
!ZipArchive methodsFor:'writing'!
addArchiveDirectory: archiveDirectoryName fromOsDirectory: osDirectoryName
- ^ self addArchiveDirectory: archiveDirectoryName fromOsDirectory: osDirectoryName compressMethod: 0
+ self addArchiveDirectory: archiveDirectoryName fromOsDirectory: osDirectoryName compressMethod: 0
+
+ "Modified: / 22-11-2018 / 15:24:18 / Stefan Vogel"
!
addArchiveDirectory: archiveDirectoryName fromOsDirectory: osDirectoryName compressMethod: theCompressMethod
@@ -4308,9 +4311,10 @@
!
addArchiveDirectoryCompressed: archiveDirectoryName fromOsDirectory: osDirectoryName
- ^ self addArchiveDirectory: archiveDirectoryName fromOsDirectory: osDirectoryName compressMethod:COMPRESSION_DEFLATED
+ self addArchiveDirectory: archiveDirectoryName fromOsDirectory: osDirectoryName compressMethod:COMPRESSION_DEFLATED
"Modified: / 19-11-2010 / 15:58:04 / cg"
+ "Modified: / 22-11-2018 / 15:24:10 / Stefan Vogel"
!
addDirectory: aDirectoryName
@@ -4319,19 +4323,23 @@
<resource: #obsolete>
self obsoleteMethodWarning.
- ^ self addFile:aDirectoryName withContents:nil compressMethod:COMPRESSION_STORED asDirectory:true.
+ self addFile:aDirectoryName withContents:nil compressMethod:COMPRESSION_STORED asDirectory:true.
"Modified: / 19-11-2010 / 15:38:59 / cg"
+ "Modified: / 22-11-2018 / 15:23:54 / Stefan Vogel"
!
addFile: aFileName fromStream: aStream
- ^ self addFile: aFileName fromStream: aStream compressMethod:COMPRESSION_STORED asDirectory:false
+ self addFile: aFileName fromStream: aStream compressMethod:COMPRESSION_STORED asDirectory:false
"Modified: / 19-11-2010 / 15:39:02 / cg"
+ "Modified: / 22-11-2018 / 12:28:27 / Stefan Vogel"
!
addFile:aFileName fromStream:aStream compressMethod: theCompressMethodArg
- ^ self addFile:aFileName fromStream:aStream compressMethod:theCompressMethodArg asDirectory:false
+ self addFile:aFileName fromStream:aStream compressMethod:theCompressMethodArg asDirectory:false
+
+ "Modified: / 22-11-2018 / 15:23:48 / Stefan Vogel"
!
addFile:aFileName fromStream:aStream compressMethod:theCompressMethodArg asDirectory:isDirectory
@@ -4341,16 +4349,16 @@
crc32 unCompressedDataSize startDataPosition nextBlockSize myZipStream|
(stream isNil or: [mode ~~ #write]) ifTrue: [
- ^ self error: 'ZipArchive not open for writing ...'.
+ self error: 'ZipArchive not open for writing ...'.
].
theCompressMethod := theCompressMethodArg.
((theCompressMethod == COMPRESSION_DEFLATED)
or:[ theCompressMethod == COMPRESSION_STORED ]) ifFalse:[
- UnsupportedZipFileFormatErrorSignal raiseRequestErrorString:'unsupported compressMethod'.
- "/ if proceeded, write as uncompressed
- theCompressMethod := COMPRESSION_STORED
+ UnsupportedZipFileFormatErrorSignal raiseRequestErrorString:'unsupported compressMethod'.
+ "/ if proceeded, write as uncompressed
+ theCompressMethod := COMPRESSION_STORED
].
zipEntry := ZipMember new default.
@@ -4360,12 +4368,12 @@
zipEntry uncompressedSize: 0.
isDirectory ifTrue: [
- theCompressMethod := COMPRESSION_STORED.
- zipEntry externalFileAttributes: EXTERNALFILEATTRIBUTES_ISDIRECTORY.
+ theCompressMethod := COMPRESSION_STORED.
+ zipEntry externalFileAttributes: EXTERNALFILEATTRIBUTES_ISDIRECTORY.
] ifFalse: [
- zipEntry compressionMethod: theCompressMethod.
- zipEntry internalFileAttributes: 1.
- zipEntry externalFileAttributes: EXTERNALFILEATTRIBUTES_ISFILE.
+ zipEntry compressionMethod: theCompressMethod.
+ zipEntry internalFileAttributes: 1.
+ zipEntry externalFileAttributes: EXTERNALFILEATTRIBUTES_ISFILE.
].
"/ data and time in msdos format
@@ -4383,28 +4391,28 @@
startDataPosition := stream position.
[
- [aStream atEnd] whileFalse: [
- nextBlockSize := aStream nextBytes:streamBufferSize into:buffer startingAt:1.
-
- nextBlockSize > 0 ifTrue: [
- unCompressedDataSize := unCompressedDataSize + nextBlockSize.
- crc32 := ZipStream crc32BytesIn: buffer from:1 to:nextBlockSize crc:crc32.
- theCompressMethod == COMPRESSION_DEFLATED ifTrue: [
- myZipStream isNil ifTrue: [
- myZipStream := ZipStream writeOpenAsZipStreamOn:stream suppressHeaderAndChecksum:true.
- ].
- myZipStream nextPutBytes:nextBlockSize from:buffer startingAt:1.
- ] ifFalse: [theCompressMethod == COMPRESSION_STORED ifTrue: [
- stream nextPutBytes:nextBlockSize from:buffer startingAt:1.
- ] ifFalse:[
- UnsupportedZipFileFormatErrorSignal raiseRequestErrorString:'unsupported compressMethod'.
- ]].
- ].
- ].
+ [aStream atEnd] whileFalse: [
+ nextBlockSize := aStream nextBytes:streamBufferSize into:buffer startingAt:1.
+
+ nextBlockSize > 0 ifTrue: [
+ unCompressedDataSize := unCompressedDataSize + nextBlockSize.
+ crc32 := ZipStream crc32BytesIn: buffer from:1 to:nextBlockSize crc:crc32.
+ theCompressMethod == COMPRESSION_DEFLATED ifTrue: [
+ myZipStream isNil ifTrue: [
+ myZipStream := ZipStream writeOpenAsZipStreamOn:stream suppressHeaderAndChecksum:true.
+ ].
+ myZipStream nextPutBytes:nextBlockSize from:buffer startingAt:1.
+ ] ifFalse: [theCompressMethod == COMPRESSION_STORED ifTrue: [
+ stream nextPutBytes:nextBlockSize from:buffer startingAt:1.
+ ] ifFalse:[
+ UnsupportedZipFileFormatErrorSignal raiseRequestErrorString:'unsupported compressMethod'.
+ ]].
+ ].
+ ].
] ensure:[
- myZipStream notNil ifTrue:[
- myZipStream close.
- ].
+ myZipStream notNil ifTrue:[
+ myZipStream close.
+ ].
].
zipEntry compressedSize:(stream position) - startDataPosition.
@@ -4419,108 +4427,114 @@
stream setToEnd.
"Modified: / 19-11-2010 / 15:39:32 / cg"
+ "Modified: / 22-11-2018 / 12:27:39 / Stefan Vogel"
!
addFile: aFileName withContents: data
- ^ self addFile: aFileName withContents: data compressMethod:COMPRESSION_STORED asDirectory: false.
+ self addFile: aFileName withContents: data compressMethod:COMPRESSION_STORED asDirectory: false.
"Modified: / 19-11-2010 / 15:39:13 / cg"
+ "Modified: / 22-11-2018 / 15:23:17 / Stefan Vogel"
!
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
+ self basicAddFile:aFileName withContents:data compressMethod:theCompressMethodArg asDirectory:isDirectory
"Modified: / 18-11-2010 / 19:31:36 / cg"
+ "Modified: / 22-11-2018 / 15:23:24 / Stefan Vogel"
!
addFileCompressed: aFileName fromStream: aStream
- ^ self addFile: aFileName fromStream: aStream compressMethod: COMPRESSION_DEFLATED asDirectory:false
+ self addFile: aFileName fromStream: aStream compressMethod: COMPRESSION_DEFLATED asDirectory:false
"Modified: / 19-11-2010 / 15:58:07 / cg"
+ "Modified: / 22-11-2018 / 15:23:29 / Stefan Vogel"
!
addFileCompressed: aFileName withContents: data
- ^ self addFile: aFileName withContents: data compressMethod: COMPRESSION_DEFLATED asDirectory: false.
+ self addFile: aFileName withContents: data compressMethod: COMPRESSION_DEFLATED asDirectory: false.
"Modified: / 19-11-2010 / 15:58:10 / cg"
+ "Modified: / 22-11-2018 / 15:23:34 / Stefan Vogel"
!
addString: aString as: path
- ^ self addFile: path fromStream: (aString readStream)
+ self addFile: path fromStream: (aString readStream)
"Modified: / 19-11-2010 / 17:47:26 / cg"
+ "Modified: / 22-11-2018 / 15:23:40 / Stefan Vogel"
!
basicAddFile:aFileName withContents:data compressMethod:theCompressMethodArg asDirectory:isDirectory
"do not create directories (isDirectory = true) - they are not compatible between operating systems"
- | zipEntry theCompressedData theZipFileName theCompressMethod compressedDataOffset|
+ |zipEntry theCompressedData theZipFileName theCompressMethod compressedDataOffset compressedDataSize|
(stream isNil or:[ mode ~~ #write ]) ifTrue:[
- ^ self error:'ZipArchive not open for writing ...'.
+ ^ self error:'ZipArchive not open for writing ...'.
].
theCompressMethod := theCompressMethodArg.
((theCompressMethod ~~ COMPRESSION_DEFLATED)
and:[theCompressMethod ~~ COMPRESSION_STORED]) ifTrue:[
- UnsupportedZipFileFormatErrorSignal
- raiseRequestErrorString:'unsupported compressMethod'.
- "/ if proceeded, write as uncompressed
- theCompressMethod := COMPRESSION_STORED
+ UnsupportedZipFileFormatErrorSignal
+ raiseRequestErrorString:'unsupported compressMethod'.
+ "/ if proceeded, write as uncompressed
+ theCompressMethod := COMPRESSION_STORED
].
zipEntry := ZipMember new default.
theZipFileName := self validZipFileNameFrom:aFileName.
- zipEntry fileName:theZipFileName.
-
- (self appendTrailingSlash and:[isDirectory]) ifTrue:[
- theZipFileName last == $/ ifFalse:[
- zipEntry fileName:theZipFileName , $/.
- zipEntry fileNameLength:theZipFileName size + 1.
- ].
+
+ (isDirectory and:[self appendTrailingSlash and:[theZipFileName last ~~ $/]]) ifTrue:[
+ zipEntry fileName:theZipFileName , $/.
+ ] ifFalse:[
+ zipEntry fileName:theZipFileName.
].
zipEntry uncompressedSize:data size.
isDirectory ifTrue:[
- zipEntry externalFileAttributes:EXTERNALFILEATTRIBUTES_ISDIRECTORY.
+ zipEntry externalFileAttributes:EXTERNALFILEATTRIBUTES_ISDIRECTORY.
] ifFalse:[
- zipEntry compressionMethod:theCompressMethod.
- zipEntry internalFileAttributes: 1.
- zipEntry externalFileAttributes: EXTERNALFILEATTRIBUTES_ISFILE.
+ zipEntry compressionMethod:theCompressMethod.
+ zipEntry internalFileAttributes: 1.
+ zipEntry externalFileAttributes: EXTERNALFILEATTRIBUTES_ISFILE.
].
"/ data and time in msdos format
zipEntry setModificationTimeAndDateToNow.
data notEmptyOrNil ifTrue:[
- "/ crc32 is always required (not as written in docu to be zero in case of uncompressed mode)
- zipEntry crc32:(ZipStream crc32BytesIn:data from:1 to:data size crc:0).
+ "/ crc32 is always required (not as written in docu to be zero in case of uncompressed mode)
+ zipEntry crc32:(ZipStream crc32BytesIn:data from:1 to:data size crc:0).
].
- (isDirectory not and:[ theCompressMethod == COMPRESSION_DEFLATED ]) ifTrue:[
- |tmpCompressedDataSize|
-
- theCompressedData := ByteArray new:(data size + 16).
- tmpCompressedDataSize := ZipStream compress:data into:theCompressedData.
- zipEntry compressedSize:tmpCompressedDataSize - 6.
- compressedDataOffset := 3.
+ (isDirectory not and:[theCompressMethod == COMPRESSION_DEFLATED]) ifTrue:[
+ theCompressedData := ByteArray new:(data size + 16).
+ compressedDataSize := (ZipStream compress:data into:theCompressedData) - 6.
+ compressedDataOffset := 3.
] ifFalse:["theCompressMethod == COMPRESSION_STORED"
- zipEntry compressedSize:zipEntry uncompressedSize.
- theCompressedData := data.
- compressedDataOffset := 1.
+ theCompressedData := data.
+ compressedDataSize := data size.
+ compressedDataOffset := 1.
].
+ zipEntry compressedSize:compressedDataSize.
"/ ensure that the file position is at the end
stream setToEnd.
zipEntry writeTo:stream.
theCompressedData notNil ifTrue:[
- stream nextPutBytes:zipEntry compressedSize from:theCompressedData startingAt:compressedDataOffset.
+ stream
+ nextPutAll:theCompressedData
+ startingAt:compressedDataOffset
+ to:compressedDataOffset + compressedDataSize - 1.
].
self addMember:zipEntry.
"Created: / 18-11-2010 / 19:31:10 / cg"
"Modified: / 19-11-2010 / 17:47:01 / cg"
"Modified: / 19-11-2012 / 12:04:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 22-11-2018 / 15:42:25 / Stefan Vogel"
! !
!ZipArchive methodsFor:'writing - stream'!
@@ -5122,25 +5136,26 @@
relativeLocalHeaderOffset := aStream position.
aStream
- nextPutInt32LSB:C_LOCAL_HEADER_SIGNATURE ;
- nextPutInt16LSB:versionNeedToExtract;
- nextPutInt16LSB:generalPurposBitFlag;
- nextPutInt16LSB:compressionMethod;
- nextPutInt16LSB:lastModFileTime;
- nextPutInt16LSB:lastModFileDate;
- nextPutInt32LSB:crc32;
- nextPutInt32LSB:compressedSize;
- nextPutInt32LSB:uncompressedSize;
- nextPutInt16LSB:self fileNameLength;
- nextPutInt16LSB:extraFieldLength;
- nextPutAll:fileName.
+ nextPutInt32:C_LOCAL_HEADER_SIGNATURE MSB:false;
+ nextPutInt16:versionNeedToExtract MSB:false;
+ nextPutInt16:generalPurposBitFlag MSB:false;
+ nextPutInt16:compressionMethod MSB:false;
+ nextPutInt16:lastModFileTime MSB:false;
+ nextPutInt16:lastModFileDate MSB:false;
+ nextPutInt32:crc32 MSB:false;
+ nextPutInt32:compressedSize MSB:false;
+ nextPutInt32:uncompressedSize MSB:false;
+ nextPutInt16:self fileNameLength MSB:false;
+ nextPutInt16:extraFieldLength MSB:false;
+ nextPutAll:fileName.
extraField notNil ifTrue: [
- self assert:(extraField size = extraFieldLength).
- aStream nextPutAll:extraField.
+ self assert:(extraField size = extraFieldLength).
+ aStream nextPutAll:extraField.
].
"Modified: / 19-11-2010 / 15:45:38 / cg"
+ "Modified: / 22-11-2018 / 15:37:03 / Stefan Vogel"
! !
!ZipArchive::ZipReadStream methodsFor:'accessing'!