ZipArchive.st
changeset 5435 116c766a2f27
parent 5367 0595a08c2bea
child 5470 416a04cb68ba
--- a/ZipArchive.st	Mon Jan 27 19:00:19 2020 +0100
+++ b/ZipArchive.st	Mon Jan 27 19:01:48 2020 +0100
@@ -3202,9 +3202,11 @@
 
 fileSize
     stream notNil ifTrue:[
-	^ stream size
+        ^ stream collectionSize
     ].
     ^ 0
+
+    "Modified: / 27-01-2020 / 18:27:47 / Stefan Vogel"
 !
 
 memberNamed:aFilename
@@ -3438,10 +3440,8 @@
 readingFrom:aPositionableStream
     "initialize the archive to read from aPositionableStream"
 
-    stream notNil ifTrue: [
-        stream ~~ aPositionableStream ifTrue: [
-            self close.
-        ].
+    (stream notNil and:[stream ~~ aPositionableStream]) ifTrue:[
+        self close.
     ].
 
     mode := #read.
@@ -3464,7 +3464,7 @@
 
     "Modified: / 21-11-2010 / 11:45:53 / cg"
     "Modified: / 22-05-2019 / 12:19:06 / Claus Gittinger"
-    "Modified: / 19-11-2019 / 14:25:09 / Stefan Vogel"
+    "Modified (format): / 27-01-2020 / 18:34:54 / Stefan Vogel"
 !
 
 reopenForReading
@@ -3589,14 +3589,16 @@
      before. In that case the archive is the complete file."
 
     startOfArchive isNil ifTrue: [
-	"/ set archive zero position
-	startOfArchive := 0.
+        "/ set archive zero position
+        startOfArchive := 0.
     ].
 
     endOfArchive isNil ifTrue: [
-	"/ set archive end position
-	endOfArchive := stream size.
+        "/ set archive end position
+        endOfArchive := stream collectionSize.
     ].
+
+    "Modified: / 27-01-2020 / 18:27:01 / Stefan Vogel"
 !
 
 validZipFileNameFrom:zipFileName
@@ -4029,45 +4031,30 @@
     size := endOfArchive - startOfArchive.
     stream position:(pos0 := endOfArchive - ECREC_SIZE - 4).
 
-    "/ set position to end of central directory record
-    ((stream nextByte ~~ ($P codePoint))
-    or:[stream nextByte ~~ ($K codePoint)
-    or:[stream nextByte ~~ 8r005
-    or:[stream nextByte ~~ 8r006]]]) ifTrue:[
-        "/ search from end of archive backwards for "end of central directory signature",
-        "/ this is necessary if the archive includes a .ZIP file comment or a digital signature
-        "/ then the end of the directory signature may be on an other position
-
-        "/ but the "end of central directory signature" must be located in the
-        "/ last 64k of the archive
-        size > 65536 ifTrue: [
-            searchEndPos := (endOfArchive - 65536).
-        ] ifFalse: [
-            searchEndPos := startOfArchive.
+    "/ search from end of archive backwards for "end of central directory signature",
+    "/ this is necessary if the archive includes a .ZIP file comment or a digital signature
+    "/ then the end of the directory signature may be on an other position
+    "/ but the "end of central directory signature" must be located in the
+    "/ last 64k of the archive
+    size > 65536 ifTrue: [
+        searchEndPos := endOfArchive - 65536.
+    ] ifFalse: [
+        searchEndPos := startOfArchive.
+    ].
+
+    [pos0 > searchEndPos] whileTrue:[
+        (stream nextByte == $P codePoint
+         and:[stream nextByte == $K codePoint
+         and:[stream nextByte == 5
+         and:[stream nextByte == 6]]]) ifTrue:[
+            ^ true
         ].
-
-        stream position: (pos0 := endOfArchive - 4).
-
-        [true] whileTrue:[
-            (stream nextByte == ($P codePoint)
-            and:[stream nextByte == ($K codePoint)
-            and:[stream nextByte == 5
-            and:[stream nextByte == 6]]]) ifTrue:[
-                ^ true
-            ].
-            stream position <= searchEndPos ifTrue: [
-                ^ false.
-            ].
-            pos0 == 0 ifTrue:[
-                ^ false.
-            ].
-            stream position: (pos0 := pos0 - 1).
-        ].
-        ^ false
+        stream position: (pos0 := pos0 - 1).
     ].
-    ^ true
-
-    "Modified: / 15-11-2019 / 19:02:40 / Stefan Vogel"
+
+    ^ false
+
+    "Modified: / 27-01-2020 / 18:11:13 / Stefan Vogel"
 !
 
 zipMembersDo:aBlock
@@ -4469,13 +4456,13 @@
 
             nextBlockSize > 0 ifTrue: [
                 unCompressedDataSize := unCompressedDataSize + nextBlockSize.
-                crc32 := ZipStream crc32BytesIn: buffer from:1 to:nextBlockSize crc:crc32.
+                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: [
+                ] ifFalse: [theCompressMethod == COMPRESSION_STORED ifTrue:[
                     stream nextPutBytes:nextBlockSize from:buffer startingAt:1.
                 ] ifFalse:[
                     UnsupportedZipFileFormatErrorSignal raiseRequestErrorString:'unsupported compressMethod'.
@@ -4501,6 +4488,7 @@
 
     "Modified: / 19-11-2010 / 15:39:32 / cg"
     "Modified: / 19-11-2019 / 14:53:35 / Stefan Vogel"
+    "Modified (format): / 27-01-2020 / 15:19:55 / Stefan Vogel"
 !
 
 addFile: aFileName withContents: data