class: ZipArchive
comment/format in:
#binaryContentsOf:
#checkZipArchive
#writingTo:
changed:
#extract:intoStream:
#inflate:to:
--- a/ZipArchive.st Mon Mar 09 18:59:21 2015 +0100
+++ b/ZipArchive.st Wed Mar 11 23:40:27 2015 +0100
@@ -3150,8 +3150,7 @@
!ZipArchive methodsFor:'Compatibility-Squeak'!
binaryContentsOf: fileName
-
- ^(self extract: fileName asString:false)
+ ^ self extract: fileName asString:false.
!
desiredCompressionMethod:aCompressionMethod
@@ -3372,7 +3371,7 @@
!
writingTo:aPositionableStream
- "initialize the archive to read from aPositionableStream"
+ "initialize the archive to write to aPositionableStream"
file notNil ifTrue: [
self closeFile.
@@ -3391,22 +3390,6 @@
!ZipArchive methodsFor:'private'!
-checkZipArchive:archiveFileName
- |isValidArchive|
-
- archiveName := archiveFileName asFilename name.
- isValidArchive := false.
- mode := #read.
- self openFile.
-
- [
- isValidArchive := self checkZipArchive.
- ] ensure:[
- self closeFile.
- ].
- ^ isValidArchive
-!
-
closeFile
"finish the zip archive and close the stream"
@@ -3631,28 +3614,28 @@
%{ /* STACK:32768 */
char *in, *out;
- if (__isByteArray(inBytes)) {
- in = __ByteArrayInstPtr(inBytes)->ba_element;
- } else if (__isString(inBytes)) {
+ if (__isByteArrayLike(inBytes)) {
+ in = __byteArrayVal(inBytes);
+ } else if (__isStringLike(inBytes)) {
in = __stringVal(inBytes);
} else {
- inflateReturnCode = __MKSMALLINT(-999);
+ inflateReturnCode = @symbol(badArgument1);
goto badArgument;
}
if (__isByteArray(outBytes)) {
- out = __ByteArrayInstPtr(outBytes)->ba_element;
+ out = __byteArrayVal(outBytes);
} else if (__isString(outBytes)) {
out = __stringVal(outBytes);
} else {
- inflateReturnCode = __MKSMALLINT(-999);
+ inflateReturnCode = @symbol(badArgument2);
goto badArgument;
}
{
- int rc;
-
- if ((rc = stx_inflate(in, out)) == 0) {
+ int rc = stx_inflate(in, out);
+
+ if (rc == 0) {
RETURN (outBytes);
}
inflateReturnCode = __MKSMALLINT(rc);
@@ -3660,8 +3643,8 @@
badArgument: ;
%}.
inflateReturnCode notNil ifTrue:[
- inflateReturnCode == -999 ifTrue:[
- self primitiveFailed:'bad argument'
+ inflateReturnCode isSymbol ifTrue:[
+ self primitiveFailed:inflateReturnCode
].
"/ bad blockType 2
@@ -3768,7 +3751,7 @@
!
checkZipArchive
- "read the zip directory into a linked-list of zipMembers"
+ "check if my file is really a zip archive. answer true or false."
|size count_in|
@@ -3791,6 +3774,22 @@
^ self searchForEndOfCentralDirectorySignature
!
+checkZipArchive:archiveFileName
+ |isValidArchive|
+
+ archiveName := archiveFileName asFilename name.
+ isValidArchive := false.
+ mode := #read.
+ self openFile.
+
+ [
+ isValidArchive := self checkZipArchive.
+ ] ensure:[
+ self closeFile.
+ ].
+ ^ isValidArchive
+!
+
findMember:name
"find a zipMember by name"
@@ -4030,71 +4029,6 @@
"Modified: / 22-12-2010 / 12:24:54 / sr"
!
-extract:fileName intoStream: aWriteStream
- "extract an entry indentified by filename into aWriteStream"
-
- self
- withPositionAndMemberFor:fileName
- do:[:zmemb :position |
- |buffer rdSize nextBlockSize streamBufferSize myZipStream|
-
- file position:position.
-
- rdSize := zmemb uncompressedSize.
- streamBufferSize := self class streamBufferSize.
- buffer := ByteArray new: streamBufferSize.
- [
- [rdSize > 0] whileTrue: [
- rdSize > (self class streamBufferSize) ifTrue: [
- nextBlockSize := streamBufferSize.
- ] ifFalse: [
- (nextBlockSize := rdSize) > 0 ifTrue: [
- buffer := ByteArray new: nextBlockSize.
- ].
- ].
-
- nextBlockSize > 0 ifTrue: [
- zmemb compressionMethod == COMPRESSION_DEFLATED ifTrue:[
- myZipStream isNil ifTrue: [
- file binary.
- myZipStream := ZipStream readOpenAsZipStreamOn: file.
- ].
- buffer := myZipStream next:nextBlockSize.
- ] ifFalse:[
- zmemb compressionMethod == COMPRESSION_STORED ifTrue:[
- file nextBytes:nextBlockSize into:buffer startingAt:1.
- ] ifFalse:[
- UnsupportedZipFileFormatErrorSignal raiseErrorString:'unsupported compressMethod'
- ].
- ].
-
- aWriteStream nextPutBytes:buffer size from:buffer startingAt:1.
- ].
- rdSize := rdSize - nextBlockSize.
- ].
- ] ensure:[
- myZipStream notNil ifTrue:[
- myZipStream close.
- ].
- ].
- ]
-
- "Modified: / 21-11-2010 / 11:56:51 / cg"
-!
-
-reopenAndExtract:fileName intoStream: aWriteStream
- "extract an entry indentified by filename into aWriteStream"
-
- file isNil ifTrue:[
- self reopenForReading.
- ].
- self extract:fileName intoStream: aWriteStream.
- file close.
- file := nil.
-
- "Created: / 21-11-2010 / 11:59:04 / cg"
-!
-
restoreOsDirectory:osDirectoryName fromArchiveDirectory: archiveDirectoryName
|osDirectory directoryAlreadyCreated archiveDirectoryNameSize|
@@ -4171,6 +4105,51 @@
!ZipArchive methodsFor:'reading - stream'!
+extract:fileName intoStream: aWriteStream
+ "extract an entry indentified by filename into aWriteStream"
+
+ self
+ withPositionAndMemberFor:fileName
+ do:[:zmemb :position |
+ |buffer rdSize compressionMethod nextBlockSize streamBufferSize myZipStream|
+
+ file position:position.
+
+ compressionMethod := zmemb compressionMethod.
+ rdSize := zmemb uncompressedSize.
+ nextBlockSize := streamBufferSize := self class streamBufferSize.
+ buffer := ByteArray new: streamBufferSize.
+ [
+ [rdSize > 0] whileTrue: [
+ rdSize < streamBufferSize ifTrue: [
+ nextBlockSize := rdSize.
+ ].
+
+ compressionMethod == COMPRESSION_DEFLATED ifTrue:[
+ myZipStream isNil ifTrue: [
+ file binary.
+ myZipStream := ZipStream readOpenAsZipStreamOn: file.
+ ].
+ myZipStream next:nextBlockSize into:buffer startingAt:1.
+ ] ifFalse:[compressionMethod == COMPRESSION_STORED ifTrue:[
+ file nextBytes:nextBlockSize into:buffer startingAt:1.
+ ] ifFalse:[
+ UnsupportedZipFileFormatErrorSignal raiseErrorString:'unsupported compressMethod'
+ ]].
+
+ aWriteStream nextPutBytes:nextBlockSize from:buffer startingAt:1.
+ rdSize := rdSize - nextBlockSize.
+ ].
+ ] ensure:[
+ myZipStream notNil ifTrue:[
+ myZipStream close.
+ ].
+ ].
+ ]
+
+ "Modified: / 21-11-2010 / 11:56:51 / cg"
+!
+
readStreamFor:nameOfFileInArchive
"open a stream on archive contents identified by nameOfFileInArchive"
@@ -4190,6 +4169,19 @@
^ (ZipReadStream zipFileStream:file zipEntry:zipEntry)
zipArchive:self.
+!
+
+reopenAndExtract:fileName intoStream: aWriteStream
+ "extract an entry indentified by filename into aWriteStream"
+
+ file isNil ifTrue:[
+ self reopenForReading.
+ ].
+ self extract:fileName intoStream: aWriteStream.
+ file close.
+ file := nil.
+
+ "Created: / 21-11-2010 / 11:59:04 / cg"
! !
!ZipArchive methodsFor:'writing'!
@@ -5242,11 +5234,11 @@
!ZipArchive class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/ZipArchive.st,v 1.115 2015-03-09 17:59:21 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/ZipArchive.st,v 1.116 2015-03-11 22:40:27 stefan Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic2/ZipArchive.st,v 1.115 2015-03-09 17:59:21 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/ZipArchive.st,v 1.116 2015-03-11 22:40:27 stefan Exp $'
! !