class: ZipArchive
factored out common code (there's alot more in here!)
comment/format in:
#dateToZipFileDate:
#timeToZipFileTime:
changed:
#addFile:fromStream:compressMethod:asDirectory:
#basicAddFile:withContents:compressMethod:asDirectory:
#writeStreamFor:compressMethod:
category of:
#dateToZipFileDate:
#timeToZipFileTime:
--- a/ZipArchive.st Tue Feb 18 12:13:28 2014 +0100
+++ b/ZipArchive.st Tue Feb 18 14:53:32 2014 +0100
@@ -3127,6 +3127,22 @@
"Modified: / 20.10.1998 / 00:30:02 / cg"
! !
+!ZipArchive class methodsFor:'utilities'!
+
+dateToZipFileDate:aDate
+ "/ data in msdos format
+ ^ (((aDate day)
+ bitOr: (aDate month bitShift: 5))
+ bitOr: (((aDate year) - 1980) bitShift: 9))
+!
+
+timeToZipFileTime:aTime
+ "/ time in msdos format
+ ^ (((aTime seconds // 2)
+ bitOr: (aTime minutes bitShift: 5))
+ bitOr: (aTime hours bitShift: 11))
+! !
+
!ZipArchive methodsFor:'Compatibility-Squeak'!
binaryContentsOf: fileName
@@ -4186,7 +4202,7 @@
addFile:aFileName fromStream:aStream compressMethod:theCompressMethodArg asDirectory:isDirectory
"do not create directories (isDirectory = true) - they are not compatible between operating systems"
- |zipEntry curTime curDate theZipFileName theCompressMethod streamBufferSize buffer
+ |zipEntry theZipFileName theCompressMethod streamBufferSize buffer
crc32 unCompressedDataSize startDataPosition nextBlockSize myZipStream|
(file isNil or: [mode ~~ #write]) ifTrue: [
@@ -4218,11 +4234,8 @@
zipEntry externalFileAttributes: EXTERNALFILEATTRIBUTES_ISFILE.
].
- curTime := Time now.
- curDate := Date today.
"/ data and time in msdos format
- zipEntry lastModFileTime: (((curTime seconds // 2) bitOr: (curTime minutes rightShift: -5)) bitOr: (curTime hours rightShift: -11)).
- zipEntry lastModFileDate: (((curDate day) bitOr: (curDate month rightShift: -5)) bitOr: (((curDate year) - 1980) rightShift: -9)).
+ zipEntry setModificationTimeAndDateToNow.
"/ ensure that the file position is at the end
file setToEnd.
@@ -4309,7 +4322,7 @@
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 |
+ | zipEntry theCompressedData theZipFileName theCompressMethod |
(file isNil or:[ mode ~~ #write ]) ifTrue:[
^ self error:'ZipArchive not open for writing ...'.
@@ -4345,18 +4358,10 @@
zipEntry internalFileAttributes: 1.
zipEntry externalFileAttributes: EXTERNALFILEATTRIBUTES_ISFILE.
].
- curTime := Time now.
- curDate := Date today.
"/ data and time in msdos format
-
- zipEntry
- lastModFileTime:(((curTime seconds // 2)
- bitOr:(curTime minutes rightShift:-5))
- bitOr:(curTime hours rightShift:-11)).
- zipEntry
- lastModFileDate:(((curDate day) bitOr:(curDate month rightShift:-5))
- bitOr:(((curDate year) - 1980) rightShift:-9)).
+ zipEntry setModificationTimeAndDateToNow.
+
data notEmptyOrNil ifTrue:[
"/ crc32 is allways reqired (not as written in docu to be zero in case of uncompressed mode)
zipEntry crc32:(ZipStream crc32BytesIn:data).
@@ -4405,7 +4410,7 @@
writeStreamFor:nameOfFileInArchive compressMethod:theCompressMethodArg
"create new entry in central directory"
- |zipEntry curTime curDate theZipFileName theCompressMethod|
+ |zipEntry theZipFileName theCompressMethod|
(file isNil or:[mode ~~ #write]) ifTrue: [
^ self error: 'ZipArchive not open for writing ...'.
@@ -4431,11 +4436,8 @@
zipEntry internalFileAttributes: 1.
zipEntry externalFileAttributes: EXTERNALFILEATTRIBUTES_ISFILE.
- curTime := Time now.
- curDate := Date today.
"/ data and time in msdos format
- zipEntry lastModFileTime: (((curTime seconds // 2) bitOr: (curTime minutes rightShift: -5)) bitOr: (curTime hours rightShift: -11)).
- zipEntry lastModFileDate: (((curDate day) bitOr: (curDate month rightShift: -5)) bitOr: (((curDate year) - 1980) rightShift: -9)).
+ zipEntry setModificationTimeAndDateToNow.
"/ ensure that the file position is at the end
file setToEnd.
@@ -4443,8 +4445,7 @@
zipEntry writeTo:file.
self addMember:zipEntry.
- ^ (ZipWriteStream zipFileStream:file zipEntry:zipEntry)
- zipArchive:self.
+ ^ (ZipWriteStream zipFileStream:file zipEntry:zipEntry) zipArchive:self.
"Modified: / 19-11-2010 / 15:38:54 / cg"
! !
@@ -4818,6 +4819,16 @@
relativeLocalHeaderOffset := something.
!
+setModificationTimeAndDateToNow
+ |curTime curDate|
+
+ curTime := Time now.
+ curDate := Date today.
+ "/ data and time in msdos format
+ self lastModFileTime: (ZipArchive timeToZipFileTime:curTime).
+ self lastModFileDate: (ZipArchive dateToZipFileDate:curDate).
+!
+
uncompressedSize
^ uncompressedSize
!
@@ -5180,11 +5191,11 @@
!ZipArchive class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/ZipArchive.st,v 1.111 2013-08-18 10:57:01 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/ZipArchive.st,v 1.112 2014-02-18 13:53:32 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic2/ZipArchive.st,v 1.111 2013-08-18 10:57:01 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/ZipArchive.st,v 1.112 2014-02-18 13:53:32 cg Exp $'
! !