ZipArchive.st
changeset 5367 0595a08c2bea
parent 5366 8726eb01e744
child 5435 116c766a2f27
--- a/ZipArchive.st	Fri Dec 13 16:00:55 2019 +0100
+++ b/ZipArchive.st	Fri Dec 13 16:49:45 2019 +0100
@@ -4141,6 +4141,35 @@
     "Modified: / 22-12-2010 / 12:24:54 / sr"
 !
 
+extract:fileName toStream:outStream
+    "extract an entry identified by fileName
+     and write it onto outStream.
+     Might raise an error"
+
+    self
+        withPositionAndMemberFor:fileName
+        do:[:zmemb :position |
+            |rawContents data nWritten compressionMethod|
+
+            stream position:position.
+            compressionMethod := zmemb compressionMethod.
+            compressionMethod == COMPRESSION_STORED ifTrue:[
+                "/ uncompressed
+                nWritten := stream copy:(zmemb compressedSize) into:outStream.
+            ] ifFalse:[
+                #TODO. "/ add support to extract without creating a temporary string (i.e. decompress directoly to the stream)
+                rawContents := stream nextBytes:(zmemb compressedSize).
+                data := self
+                            decode:rawContents method:compressionMethod
+                            size:(zmemb uncompressedSize)
+                            asString:(outStream isBinary not).
+                outStream nextPutAll:data.
+                nWritten := data size
+            ].
+            ^ nWritten.
+        ].
+!
+
 nextBytes: bytesToRead of: zmember startingAt: pos into: b startingAt: off
 
     stream position: (self dataStartOf: zmember) + startOfArchive + pos.