Addec trailing slash behavior (enabled by default)
authorJan Vrany <jan.vrany@fit.cvut.cz>
Mon, 19 Nov 2012 13:07:06 +0100
changeset 2855 568bf375326c
parent 2854 d6a139bccf99
child 2856 fe5136a71187
Addec trailing slash behavior (enabled by default)
ZipArchive.st
--- a/ZipArchive.st	Tue Nov 13 14:05:13 2012 +0100
+++ b/ZipArchive.st	Mon Nov 19 13:07:06 2012 +0100
@@ -13,9 +13,9 @@
 
 Object subclass:#ZipArchive
 	instanceVariableNames:'file mode archiveName firstEntry lastEntry centralDirectory
-		startOfArchive endOfArchive zipMembersByName'
+		startOfArchive endOfArchive zipMembersByName appendTrailingSlash'
 	classVariableNames:'Lobby RecentlyUsedZipArchives FlushBlock ZipFileFormatErrorSignal
-		UnsupportedZipFileFormatErrorSignal'
+		UnsupportedZipFileFormatErrorSignal DefaultAppendTrailingSlash'
 	poolDictionaries:'ZipArchiveConstants'
 	category:'System-Support-FileFormats'
 !
@@ -1035,11 +1035,32 @@
 documentation
 "
     provides access to a zip archive.
+
+
+    Trailing slash.
+        Some implementations require a trailing slash in directory
+        names (such as OpenOffice zip implementation). Others just
+        ignore external file attrbutes and indicate directory entry
+        by adding trailing slash (such a Java zip implementation).
+
+        Since ZipArchive 1.98 a trailing slash is added for all directory
+        entries iff appendTrailingSlash instvar is set to true. By default 
+        it set to value of DefaultAppendTrailingSlash which defaults to true.
+
+        Setting appendTrailingSlash to false inhibits trailing slash
+        behavior.
+        
+
     Caveat: 
         the only compression methods (for now) are store and deflate.
 
     [author:]
         Claus Gittinger
+
+    [classvars:]
+        DefaultAppendTrailingSlash...a default value for appendTralingSlash instvar.
+                                     For details, se above
+
 "
 !
 
@@ -2931,6 +2952,7 @@
     ^ ZipFileFormatErrorSignal
 ! !
 
+
 !ZipArchive class methodsFor:'class initialization'!
 
 initialize
@@ -2948,11 +2970,14 @@
         Lobby := Registry new.
     ].
 
+    DefaultAppendTrailingSlash := true.
+
     "
      self initialize
     "
 
     "Modified: / 19-11-2010 / 15:44:28 / cg"
+    "Modified: / 19-11-2012 / 11:53:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !ZipArchive class methodsFor:'cleanup'!
@@ -3986,6 +4011,7 @@
     "Created: / 21-11-2010 / 11:51:41 / cg"
 ! !
 
+
 !ZipArchive methodsFor:'reading - stream'!
 
 readStreamFor:nameOfFileInArchive
@@ -4194,80 +4220,6 @@
     ^ 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.
-    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). "/ if the compression is less then the additional overhead we need more space in buffer
-        tmpCompressedDataSize := ZipStream compress:data into:tmpCompressedData.
-
-        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 == 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"
 ! !
 
 !ZipArchive methodsFor:'writing - stream'!
@@ -4769,9 +4721,12 @@
 !
 
 isDirectory
-    ^ (externalFileAttributes ? 0) bitTest:EXTERNALFILEATTRIBUTES_ISDIRECTORY
+    ^ 
+    ((externalFileAttributes ? 0) bitTest:EXTERNALFILEATTRIBUTES_ISDIRECTORY)
+        or:[uncompressedSize == 0 and:[fileName last = $/]].
 
     "Created: / 28-03-2011 / 19:19:26 / cg"
+    "Modified: / 19-11-2012 / 12:02:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !ZipArchive::ZipMember methodsFor:'reading & writing'!
@@ -5064,11 +5019,11 @@
 !ZipArchive class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/ZipArchive.st,v 1.97 2012-10-25 22:01:52 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/ZipArchive.st,v 1.98 2012-11-19 12:07:06 vrany Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic2/ZipArchive.st,v 1.97 2012-10-25 22:01:52 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/ZipArchive.st,v 1.98 2012-11-19 12:07:06 vrany Exp $'
 ! !
 
 ZipArchive initialize!