3629 |inflateReturnCode| |
3612 |inflateReturnCode| |
3630 |
3613 |
3631 %{ /* STACK:32768 */ |
3614 %{ /* STACK:32768 */ |
3632 char *in, *out; |
3615 char *in, *out; |
3633 |
3616 |
3634 if (__isByteArray(inBytes)) { |
3617 if (__isByteArrayLike(inBytes)) { |
3635 in = __ByteArrayInstPtr(inBytes)->ba_element; |
3618 in = __byteArrayVal(inBytes); |
3636 } else if (__isString(inBytes)) { |
3619 } else if (__isStringLike(inBytes)) { |
3637 in = __stringVal(inBytes); |
3620 in = __stringVal(inBytes); |
3638 } else { |
3621 } else { |
3639 inflateReturnCode = __MKSMALLINT(-999); |
3622 inflateReturnCode = @symbol(badArgument1); |
3640 goto badArgument; |
3623 goto badArgument; |
3641 } |
3624 } |
3642 |
3625 |
3643 if (__isByteArray(outBytes)) { |
3626 if (__isByteArray(outBytes)) { |
3644 out = __ByteArrayInstPtr(outBytes)->ba_element; |
3627 out = __byteArrayVal(outBytes); |
3645 } else if (__isString(outBytes)) { |
3628 } else if (__isString(outBytes)) { |
3646 out = __stringVal(outBytes); |
3629 out = __stringVal(outBytes); |
3647 } else { |
3630 } else { |
3648 inflateReturnCode = __MKSMALLINT(-999); |
3631 inflateReturnCode = @symbol(badArgument2); |
3649 goto badArgument; |
3632 goto badArgument; |
3650 } |
3633 } |
3651 |
3634 |
3652 { |
3635 { |
3653 int rc; |
3636 int rc = stx_inflate(in, out); |
3654 |
3637 |
3655 if ((rc = stx_inflate(in, out)) == 0) { |
3638 if (rc == 0) { |
3656 RETURN (outBytes); |
3639 RETURN (outBytes); |
3657 } |
3640 } |
3658 inflateReturnCode = __MKSMALLINT(rc); |
3641 inflateReturnCode = __MKSMALLINT(rc); |
3659 } |
3642 } |
3660 badArgument: ; |
3643 badArgument: ; |
3661 %}. |
3644 %}. |
3662 inflateReturnCode notNil ifTrue:[ |
3645 inflateReturnCode notNil ifTrue:[ |
3663 inflateReturnCode == -999 ifTrue:[ |
3646 inflateReturnCode isSymbol ifTrue:[ |
3664 self primitiveFailed:'bad argument' |
3647 self primitiveFailed:inflateReturnCode |
3665 ]. |
3648 ]. |
3666 |
3649 |
3667 "/ bad blockType 2 |
3650 "/ bad blockType 2 |
3668 self error:'inflate error: ' , inflateReturnCode printString |
3651 self error:'inflate error: ' , inflateReturnCode printString |
3669 ]. |
3652 ]. |
4026 |
4025 |
4027 ^ nil |
4026 ^ nil |
4028 |
4027 |
4029 "Modified: / 21-11-2010 / 11:53:00 / cg" |
4028 "Modified: / 21-11-2010 / 11:53:00 / cg" |
4030 "Modified: / 22-12-2010 / 12:24:54 / sr" |
4029 "Modified: / 22-12-2010 / 12:24:54 / sr" |
4031 ! |
|
4032 |
|
4033 extract:fileName intoStream: aWriteStream |
|
4034 "extract an entry indentified by filename into aWriteStream" |
|
4035 |
|
4036 self |
|
4037 withPositionAndMemberFor:fileName |
|
4038 do:[:zmemb :position | |
|
4039 |buffer rdSize nextBlockSize streamBufferSize myZipStream| |
|
4040 |
|
4041 file position:position. |
|
4042 |
|
4043 rdSize := zmemb uncompressedSize. |
|
4044 streamBufferSize := self class streamBufferSize. |
|
4045 buffer := ByteArray new: streamBufferSize. |
|
4046 [ |
|
4047 [rdSize > 0] whileTrue: [ |
|
4048 rdSize > (self class streamBufferSize) ifTrue: [ |
|
4049 nextBlockSize := streamBufferSize. |
|
4050 ] ifFalse: [ |
|
4051 (nextBlockSize := rdSize) > 0 ifTrue: [ |
|
4052 buffer := ByteArray new: nextBlockSize. |
|
4053 ]. |
|
4054 ]. |
|
4055 |
|
4056 nextBlockSize > 0 ifTrue: [ |
|
4057 zmemb compressionMethod == COMPRESSION_DEFLATED ifTrue:[ |
|
4058 myZipStream isNil ifTrue: [ |
|
4059 file binary. |
|
4060 myZipStream := ZipStream readOpenAsZipStreamOn: file. |
|
4061 ]. |
|
4062 buffer := myZipStream next:nextBlockSize. |
|
4063 ] ifFalse:[ |
|
4064 zmemb compressionMethod == COMPRESSION_STORED ifTrue:[ |
|
4065 file nextBytes:nextBlockSize into:buffer startingAt:1. |
|
4066 ] ifFalse:[ |
|
4067 UnsupportedZipFileFormatErrorSignal raiseErrorString:'unsupported compressMethod' |
|
4068 ]. |
|
4069 ]. |
|
4070 |
|
4071 aWriteStream nextPutBytes:buffer size from:buffer startingAt:1. |
|
4072 ]. |
|
4073 rdSize := rdSize - nextBlockSize. |
|
4074 ]. |
|
4075 ] ensure:[ |
|
4076 myZipStream notNil ifTrue:[ |
|
4077 myZipStream close. |
|
4078 ]. |
|
4079 ]. |
|
4080 ] |
|
4081 |
|
4082 "Modified: / 21-11-2010 / 11:56:51 / cg" |
|
4083 ! |
|
4084 |
|
4085 reopenAndExtract:fileName intoStream: aWriteStream |
|
4086 "extract an entry indentified by filename into aWriteStream" |
|
4087 |
|
4088 file isNil ifTrue:[ |
|
4089 self reopenForReading. |
|
4090 ]. |
|
4091 self extract:fileName intoStream: aWriteStream. |
|
4092 file close. |
|
4093 file := nil. |
|
4094 |
|
4095 "Created: / 21-11-2010 / 11:59:04 / cg" |
|
4096 ! |
4030 ! |
4097 |
4031 |
4098 restoreOsDirectory:osDirectoryName fromArchiveDirectory: archiveDirectoryName |
4032 restoreOsDirectory:osDirectoryName fromArchiveDirectory: archiveDirectoryName |
4099 |osDirectory directoryAlreadyCreated archiveDirectoryNameSize| |
4033 |osDirectory directoryAlreadyCreated archiveDirectoryNameSize| |
4100 |
4034 |
4169 ! ! |
4103 ! ! |
4170 |
4104 |
4171 |
4105 |
4172 !ZipArchive methodsFor:'reading - stream'! |
4106 !ZipArchive methodsFor:'reading - stream'! |
4173 |
4107 |
|
4108 extract:fileName intoStream: aWriteStream |
|
4109 "extract an entry indentified by filename into aWriteStream" |
|
4110 |
|
4111 self |
|
4112 withPositionAndMemberFor:fileName |
|
4113 do:[:zmemb :position | |
|
4114 |buffer rdSize compressionMethod nextBlockSize streamBufferSize myZipStream| |
|
4115 |
|
4116 file position:position. |
|
4117 |
|
4118 compressionMethod := zmemb compressionMethod. |
|
4119 rdSize := zmemb uncompressedSize. |
|
4120 nextBlockSize := streamBufferSize := self class streamBufferSize. |
|
4121 buffer := ByteArray new: streamBufferSize. |
|
4122 [ |
|
4123 [rdSize > 0] whileTrue: [ |
|
4124 rdSize < streamBufferSize ifTrue: [ |
|
4125 nextBlockSize := rdSize. |
|
4126 ]. |
|
4127 |
|
4128 compressionMethod == COMPRESSION_DEFLATED ifTrue:[ |
|
4129 myZipStream isNil ifTrue: [ |
|
4130 file binary. |
|
4131 myZipStream := ZipStream readOpenAsZipStreamOn: file. |
|
4132 ]. |
|
4133 myZipStream next:nextBlockSize into:buffer startingAt:1. |
|
4134 ] ifFalse:[compressionMethod == COMPRESSION_STORED ifTrue:[ |
|
4135 file nextBytes:nextBlockSize into:buffer startingAt:1. |
|
4136 ] ifFalse:[ |
|
4137 UnsupportedZipFileFormatErrorSignal raiseErrorString:'unsupported compressMethod' |
|
4138 ]]. |
|
4139 |
|
4140 aWriteStream nextPutBytes:nextBlockSize from:buffer startingAt:1. |
|
4141 rdSize := rdSize - nextBlockSize. |
|
4142 ]. |
|
4143 ] ensure:[ |
|
4144 myZipStream notNil ifTrue:[ |
|
4145 myZipStream close. |
|
4146 ]. |
|
4147 ]. |
|
4148 ] |
|
4149 |
|
4150 "Modified: / 21-11-2010 / 11:56:51 / cg" |
|
4151 ! |
|
4152 |
4174 readStreamFor:nameOfFileInArchive |
4153 readStreamFor:nameOfFileInArchive |
4175 "open a stream on archive contents identified by nameOfFileInArchive" |
4154 "open a stream on archive contents identified by nameOfFileInArchive" |
4176 |
4155 |
4177 |zipEntry dataStart| |
4156 |zipEntry dataStart| |
4178 |
4157 |
4188 dataStart := self dataStartOf:zipEntry. |
4167 dataStart := self dataStartOf:zipEntry. |
4189 file position:dataStart. |
4168 file position:dataStart. |
4190 |
4169 |
4191 ^ (ZipReadStream zipFileStream:file zipEntry:zipEntry) |
4170 ^ (ZipReadStream zipFileStream:file zipEntry:zipEntry) |
4192 zipArchive:self. |
4171 zipArchive:self. |
|
4172 ! |
|
4173 |
|
4174 reopenAndExtract:fileName intoStream: aWriteStream |
|
4175 "extract an entry indentified by filename into aWriteStream" |
|
4176 |
|
4177 file isNil ifTrue:[ |
|
4178 self reopenForReading. |
|
4179 ]. |
|
4180 self extract:fileName intoStream: aWriteStream. |
|
4181 file close. |
|
4182 file := nil. |
|
4183 |
|
4184 "Created: / 21-11-2010 / 11:59:04 / cg" |
4193 ! ! |
4185 ! ! |
4194 |
4186 |
4195 !ZipArchive methodsFor:'writing'! |
4187 !ZipArchive methodsFor:'writing'! |
4196 |
4188 |
4197 addArchiveDirectory: archiveDirectoryName fromOsDirectory: osDirectoryName |
4189 addArchiveDirectory: archiveDirectoryName fromOsDirectory: osDirectoryName |
5240 ! ! |
5232 ! ! |
5241 |
5233 |
5242 !ZipArchive class methodsFor:'documentation'! |
5234 !ZipArchive class methodsFor:'documentation'! |
5243 |
5235 |
5244 version |
5236 version |
5245 ^ '$Header: /cvs/stx/stx/libbasic2/ZipArchive.st,v 1.115 2015-03-09 17:59:21 cg Exp $' |
5237 ^ '$Header: /cvs/stx/stx/libbasic2/ZipArchive.st,v 1.116 2015-03-11 22:40:27 stefan Exp $' |
5246 ! |
5238 ! |
5247 |
5239 |
5248 version_CVS |
5240 version_CVS |
5249 ^ '$Header: /cvs/stx/stx/libbasic2/ZipArchive.st,v 1.115 2015-03-09 17:59:21 cg Exp $' |
5241 ^ '$Header: /cvs/stx/stx/libbasic2/ZipArchive.st,v 1.116 2015-03-11 22:40:27 stefan Exp $' |
5250 ! ! |
5242 ! ! |
5251 |
5243 |
5252 |
5244 |
5253 ZipArchive initialize! |
5245 ZipArchive initialize! |