Fix for previous commit (pressed wrong CVS dialog)
authorJan Vrany <jan.vrany@fit.cvut.cz>
Mon, 19 Nov 2012 13:09:20 +0100
changeset 2856 fe5136a71187
parent 2855 568bf375326c
child 2857 6934efb6b22d
Fix for previous commit (pressed wrong CVS dialog)
ZipArchive.st
--- a/ZipArchive.st	Mon Nov 19 13:07:06 2012 +0100
+++ b/ZipArchive.st	Mon Nov 19 13:09:20 2012 +0100
@@ -2952,6 +2952,24 @@
     ^ ZipFileFormatErrorSignal
 ! !
 
+!ZipArchive class methodsFor:'accessing-default'!
+
+defaultAppendTrailingSlash
+    "Returns default trailing slash behavior, For details,
+     see class documentation"
+
+    ^DefaultAppendTrailingSlash
+
+    "Created: / 19-11-2012 / 11:53:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+defaultAppendTrailingSlash: aBoolean
+    "Sets the default trailing slash behavior, For details,
+     see class documentation"
+    DefaultAppendTrailingSlash := aBoolean
+
+    "Created: / 19-11-2012 / 11:53:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
 
 !ZipArchive class methodsFor:'class initialization'!
 
@@ -3113,6 +3131,28 @@
 
 !ZipArchive methodsFor:'accessing'!
 
+appendTrailingSlash
+    "Returns default trailing slash behavior, For details,
+     see class documentation"
+
+    appendTrailingSlash isNil ifTrue:[
+        appendTrailingSlash := DefaultAppendTrailingSlash 
+    ].
+    ^appendTrailingSlash
+
+    "Modified: / 19-11-2012 / 12:04:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+appendTrailingSlash:aBoolean
+    "Sets trailing slash behavior. If true, all directory entries
+     will have a trailing slash in its nama. For details, see class 
+     documentation"
+
+    appendTrailingSlash := aBoolean.
+
+    "Modified (comment): / 19-11-2012 / 12:01:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 entries
     "return a collection of fileName entries"
 
@@ -4220,6 +4260,92 @@
     ^ self addFile: path fromStream: (aString readStream)
 
     "Modified: / 19-11-2010 / 17:47:26 / cg"
+!
+
+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 |
+
+    (file isNil or:[ mode ~~ #write ]) ifTrue:[
+        ^ 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
+            ].
+    zipEntry := ZipMember new default.
+    self addMember:zipEntry.
+    theZipFileName := self validZipFileNameFrom:aFileName.
+    zipEntry fileName:theZipFileName.
+    zipEntry fileNameLength:theZipFileName size.
+
+    (self appendTrailingSlash and:[isDirectory]) ifTrue:[
+        theZipFileName last == $/ ifFalse:[
+            zipEntry fileName:theZipFileName , $/.
+            zipEntry fileNameLength:theZipFileName size + 1.
+        ].
+    ].
+
+    zipEntry uncompressedSize:data size.
+    isDirectory ifTrue:[
+        zipEntry externalFileAttributes:EXTERNALFILEATTRIBUTES_ISDIRECTORY.
+    ] ifFalse:[
+        zipEntry compressionMethod:theCompressMethod.        
+        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)).
+    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).
+    ].
+    (isDirectory not and:[ theCompressMethod == COMPRESSION_DEFLATED ]) ifTrue:[
+        | tmpCompressedData  tmpCompressedDataSize |
+
+        tmpCompressedData := ByteArray new:(data size + 16).
+        tmpCompressedDataSize := ZipStream compress:data into:tmpCompressedData.
+        zipEntry compressedSize:(tmpCompressedDataSize - 6).
+        theCompressedData := tmpCompressedData copyFrom:3.
+    ] ifFalse:[
+        theCompressMethod == COMPRESSION_STORED ifTrue:[
+            zipEntry compressedSize:zipEntry uncompressedSize.
+            theCompressedData := data.
+        ] ifFalse:[
+            self error
+            "/ cannot happen
+        ].
+    ].
+    
+    "/ ensure that the file position is at the end
+    
+    file setToEnd.
+    zipEntry writeTo:file.
+    theCompressedData notNil ifTrue:[
+        file nextPutBytes:zipEntry compressedSize from:theCompressedData.
+    ].
+
+    "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>"
 ! !
 
 !ZipArchive methodsFor:'writing - stream'!
@@ -5019,11 +5145,11 @@
 !ZipArchive class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/ZipArchive.st,v 1.98 2012-11-19 12:07:06 vrany Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/ZipArchive.st,v 1.99 2012-11-19 12:09:20 vrany Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic2/ZipArchive.st,v 1.98 2012-11-19 12:07:06 vrany Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/ZipArchive.st,v 1.99 2012-11-19 12:09:20 vrany Exp $'
 ! !
 
 ZipArchive initialize!