#REFACTORING by stefan
authorStefan Vogel <sv@exept.de>
Wed, 19 Oct 2016 10:53:39 +0200
changeset 4175 95c1518f25cf
parent 4174 49c5d5174724
child 4176 bf554d531f23
#REFACTORING by stefan class: ZipArchive changed:6 methods
ZipArchive.st
--- a/ZipArchive.st	Wed Oct 19 08:12:29 2016 +0200
+++ b/ZipArchive.st	Wed Oct 19 10:53:39 2016 +0200
@@ -3256,8 +3256,10 @@
 close
     file notNil ifTrue:[
         self flush.
-        self closeFile.
-    ]
+        file close.
+        file := archiveName := centralDirectory := zipMembersByName := nil.
+        firstEntry := lastEntry := nil.
+    ].
 !
 
 flush
@@ -3382,15 +3384,12 @@
 !ZipArchive methodsFor:'private'!
 
 closeFile
-    "finish the zip archive and close the stream"
-
-    |savedFile|
-
-    file notNil ifTrue:[
-        savedFile := file.
-        file := nil.
-        savedFile close.
-    ]
+    <resource: #obsolete>
+    "backward compatibility"
+
+    self obsoleteMethodWarning:'use #close'.
+
+    self close.
 !
 
 dataStartOf:zipEntry
@@ -3730,7 +3729,7 @@
         "ignore duplicate entries for backward compatibility.
          Argh: expecco once added wrong duplicates to the end of ets files.
                The first entry is valid."
-        ('stx [Info]: Duplicate entry in ZIP (ignored): ', zmemb fileName) infoPrintCR.
+        Logger warning:'duplicate entry in ZIP file ignored: %1' with:zmemb fileName.
     ] ifFalse:[
         zipMembersByName at:zmemb fileName put:zmemb.
     ].
@@ -4254,7 +4253,6 @@
     theZipFileName := self validZipFileNameFrom:aFileName. 
 
     zipEntry fileName: theZipFileName.
-    zipEntry fileNameLength: theZipFileName size.
     zipEntry uncompressedSize: 0.
 
     isDirectory ifTrue: [
@@ -4354,26 +4352,23 @@
 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 |
+    | zipEntry theCompressedData theZipFileName theCompressMethod  compressedDataOffset|
 
     (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
-            ].
+    ((theCompressMethod ~~ COMPRESSION_DEFLATED) 
+      and:[theCompressMethod ~~ COMPRESSION_STORED]) ifTrue:[
+        UnsupportedZipFileFormatErrorSignal 
+            raiseRequestErrorString:'unsupported compressMethod'.
+        "/ if proceeded, write as uncompressed
+        theCompressMethod := COMPRESSION_STORED
+    ].
+
     zipEntry := ZipMember new default.
     theZipFileName := self validZipFileNameFrom:aFileName.
     zipEntry fileName:theZipFileName.
-    zipEntry fileNameLength:theZipFileName size.
 
     (self appendTrailingSlash and:[isDirectory]) ifTrue:[
         theZipFileName last == $/ ifFalse:[
@@ -4399,28 +4394,23 @@
         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
-        ].
+        |tmpCompressedDataSize|
+
+        theCompressedData := ByteArray new:(data size + 16).
+        tmpCompressedDataSize := ZipStream compress:data into:theCompressedData.
+        zipEntry compressedSize:tmpCompressedDataSize - 6.
+        compressedDataOffset := 3.
+    ] ifFalse:["theCompressMethod == COMPRESSION_STORED"
+        zipEntry compressedSize:zipEntry uncompressedSize.
+        theCompressedData := data.
+        compressedDataOffset := 0.
     ].
     
     "/ ensure that the file position is at the end
-    
     file setToEnd.
     zipEntry writeTo:file.
     theCompressedData notNil ifTrue:[
-        file nextPutBytes:zipEntry compressedSize from:theCompressedData.
+        file nextPutBytes:zipEntry compressedSize from:theCompressedData startingAt:compressedDataOffset.
     ].
     self addMember:zipEntry.
 
@@ -4451,7 +4441,7 @@
     theCompressMethod := theCompressMethodArg.
 
     ((theCompressMethod == COMPRESSION_DEFLATED) 
-    or:[ theCompressMethod == COMPRESSION_STORED ]) ifFalse:[
+     or:[theCompressMethod == COMPRESSION_STORED]) ifFalse:[
         UnsupportedZipFileFormatErrorSignal raiseRequestErrorString:'unsupported compressMethod'.
         "/ if proceeded, write as uncompressed
         theCompressMethod := COMPRESSION_STORED
@@ -4461,7 +4451,6 @@
     theZipFileName := self validZipFileNameFrom:nameOfFileInArchive. 
 
     zipEntry fileName: theZipFileName.
-    zipEntry fileNameLength: theZipFileName size.
     zipEntry uncompressedSize: 0.
 
     zipEntry compressionMethod: theCompressMethod.
@@ -4788,6 +4777,9 @@
 !
 
 fileNameLength
+    fileNameLength isNil ifTrue:[
+        ^ fileName size.
+    ].
     ^ fileNameLength
 !
 
@@ -4897,14 +4889,13 @@
     crc32 := 0.
     compressedSize := 0.
     uncompressedSize := 0.
-    fileNameLength := 0.
     extraFieldLength := 0.
     fileCommentLength := 0.
     diskNumberStart := 0.
     internalFileAttributes := 0.
     externalFileAttributes := 0.
     relativeLocalHeaderOffset := 0.
-    fileName := nil.
+    fileName := fileNameLength := nil.
     extraField := nil.
     fileComment := nil.
     dataStart := 0.
@@ -5004,7 +4995,7 @@
         nextPutInt32LSB:crc32;
         nextPutInt32LSB:compressedSize;
         nextPutInt32LSB:uncompressedSize;
-        nextPutInt16LSB:fileNameLength;
+        nextPutInt16LSB:self fileNameLength;
         nextPutInt16LSB:extraFieldLength;
         nextPutAll:fileName.