ZipArchive.st
changeset 4677 a73ebe9d10cb
parent 4633 d3bd3c9cc3d1
child 4680 2675216b9dd7
equal deleted inserted replaced
4676:e9e8de763fb7 4677:a73ebe9d10cb
    24 	poolDictionaries:'ZipArchiveConstants'
    24 	poolDictionaries:'ZipArchiveConstants'
    25 	category:'System-Support-FileFormats'
    25 	category:'System-Support-FileFormats'
    26 !
    26 !
    27 
    27 
    28 PeekableStream subclass:#AbstractZipStream
    28 PeekableStream subclass:#AbstractZipStream
    29 	instanceVariableNames:'zipArchive zipEntry zipFileStream compressingStream crc32
    29 	instanceVariableNames:'zipArchive zipEntry zipFileStream compressingStream
    30 		uncompressedDataSize startDataPosition'
    30 		uncompressedDataSize startDataPosition'
    31 	classVariableNames:''
    31 	classVariableNames:''
    32 	poolDictionaries:''
    32 	poolDictionaries:''
    33 	privateIn:ZipArchive
    33 	privateIn:ZipArchive
    34 !
    34 !
    62 	poolDictionaries:'ZipArchiveConstants'
    62 	poolDictionaries:'ZipArchiveConstants'
    63 	privateIn:ZipArchive
    63 	privateIn:ZipArchive
    64 !
    64 !
    65 
    65 
    66 ZipArchive::AbstractZipStream subclass:#ZipWriteStream
    66 ZipArchive::AbstractZipStream subclass:#ZipWriteStream
    67 	instanceVariableNames:''
    67 	instanceVariableNames:'crc32'
    68 	classVariableNames:''
    68 	classVariableNames:''
    69 	poolDictionaries:'ZipArchiveConstants'
    69 	poolDictionaries:'ZipArchiveConstants'
    70 	privateIn:ZipArchive
    70 	privateIn:ZipArchive
    71 !
    71 !
    72 
    72 
  4580 
  4580 
  4581 zipFileStream:something zipEntry:compressionMethodArg
  4581 zipFileStream:something zipEntry:compressionMethodArg
  4582     ^ self basicNew zipFileStream:something zipEntry:compressionMethodArg
  4582     ^ self basicNew zipFileStream:something zipEntry:compressionMethodArg
  4583 ! !
  4583 ! !
  4584 
  4584 
       
  4585 !ZipArchive::AbstractZipStream class methodsFor:'queries'!
       
  4586 
       
  4587 isAbstract
       
  4588     "Return if this class is an abstract class.
       
  4589      True is returned here for myself only; false for subclasses.
       
  4590      Abstract subclasses must redefine this again."
       
  4591 
       
  4592     ^ self == ZipArchive::AbstractZipStream.
       
  4593 ! !
       
  4594 
  4585 !ZipArchive::AbstractZipStream methodsFor:'accessing'!
  4595 !ZipArchive::AbstractZipStream methodsFor:'accessing'!
  4586 
  4596 
  4587 zipArchive
  4597 zipArchive
  4588     ^ zipArchive
  4598     ^ zipArchive
  4589 !
  4599 !
  4600     zipEntry := something.
  4610     zipEntry := something.
  4601 !
  4611 !
  4602 
  4612 
  4603 zipFileStream
  4613 zipFileStream
  4604     ^ zipFileStream
  4614     ^ zipFileStream
       
  4615 ! !
       
  4616 
       
  4617 !ZipArchive::AbstractZipStream methodsFor:'closing'!
       
  4618 
       
  4619 close
       
  4620     (compressingStream notNil and:[compressingStream ~~ zipFileStream]) ifTrue:[
       
  4621         "close ZipStream"
       
  4622         compressingStream close.
       
  4623     ].
       
  4624     compressingStream := nil.
       
  4625 
       
  4626     "Modified: / 11-06-2018 / 14:14:26 / Stefan Vogel"
       
  4627 ! !
       
  4628 
       
  4629 !ZipArchive::AbstractZipStream methodsFor:'initialization'!
       
  4630 
       
  4631 zipFileStream:zipFileStreamArg zipEntry:zipEntryArg
       
  4632     "raise an error: must be redefined in concrete subclass(es)"
       
  4633 
       
  4634     ^ self subclassResponsibility
       
  4635 
       
  4636     "Modified (format): / 11-06-2018 / 14:53:22 / Stefan Vogel"
  4605 ! !
  4637 ! !
  4606 
  4638 
  4607 !ZipArchive::AbstractZipStream methodsFor:'misc'!
  4639 !ZipArchive::AbstractZipStream methodsFor:'misc'!
  4608 
  4640 
  4609 binary
  4641 binary
  5118     ^ uncompressedDataSize
  5150     ^ uncompressedDataSize
  5119 
  5151 
  5120     "Created: / 30-05-2017 / 20:19:18 / mawalch"
  5152     "Created: / 30-05-2017 / 20:19:18 / mawalch"
  5121 ! !
  5153 ! !
  5122 
  5154 
  5123 !ZipArchive::ZipReadStream methodsFor:'closing'!
       
  5124 
       
  5125 close
       
  5126     "nothing to do here"
       
  5127 ! !
       
  5128 
       
  5129 !ZipArchive::ZipReadStream methodsFor:'initialization'!
  5155 !ZipArchive::ZipReadStream methodsFor:'initialization'!
  5130 
  5156 
       
  5157 reset
       
  5158     "reset the stream to the initial position"
       
  5159 
       
  5160     readPosition := 0.
       
  5161     peek := nil.
       
  5162 
       
  5163     zipEntry compressionMethod == COMPRESSION_DEFLATED ifTrue:[
       
  5164         compressingStream notNil ifTrue:[
       
  5165             compressingStream close.
       
  5166         ].
       
  5167         compressingStream := ZipStream readOpenAsZipStreamOn:zipFileStream suppressHeaderAndChecksum:true.
       
  5168     ] ifFalse:[
       
  5169         compressingStream := zipFileStream.
       
  5170         compressingStream text.
       
  5171     ].
       
  5172 
       
  5173     "Created: / 11-06-2018 / 14:03:51 / Stefan Vogel"
       
  5174 !
       
  5175 
  5131 zipFileStream:something zipEntry:aZipEntry
  5176 zipFileStream:something zipEntry:aZipEntry
  5132 
       
  5133     zipEntry := aZipEntry.
  5177     zipEntry := aZipEntry.
  5134     zipFileStream := something.
  5178     zipFileStream := something.
  5135     startDataPosition := zipFileStream position.
  5179     startDataPosition := zipFileStream position.
  5136     crc32 := 0.
       
  5137     uncompressedDataSize := zipEntry uncompressedSize.
  5180     uncompressedDataSize := zipEntry uncompressedSize.
  5138     readPosition := 0.
  5181 
  5139 
  5182     self reset.
  5140     zipEntry compressionMethod == COMPRESSION_DEFLATED ifTrue:[
       
  5141 	compressingStream := ZipStream readOpenAsZipStreamOn:zipFileStream suppressHeaderAndChecksum:true.
       
  5142     ] ifFalse:[
       
  5143 	compressingStream := zipFileStream.
       
  5144 	compressingStream text.
       
  5145     ].
       
  5146 
  5183 
  5147     "Modified: / 19-11-2010 / 15:47:14 / cg"
  5184     "Modified: / 19-11-2010 / 15:47:14 / cg"
  5148     "Modified (format): / 30-05-2017 / 20:17:24 / mawalch"
  5185     "Modified (format): / 30-05-2017 / 20:17:24 / mawalch"
       
  5186     "Modified: / 11-06-2018 / 14:06:58 / Stefan Vogel"
  5149 ! !
  5187 ! !
  5150 
  5188 
  5151 !ZipArchive::ZipReadStream methodsFor:'queries'!
  5189 !ZipArchive::ZipReadStream methodsFor:'queries'!
  5152 
  5190 
  5153 atEnd
  5191 atEnd
  5218 !ZipArchive::ZipWriteStream methodsFor:'closing'!
  5256 !ZipArchive::ZipWriteStream methodsFor:'closing'!
  5219 
  5257 
  5220 close
  5258 close
  5221     "finalize the data"
  5259     "finalize the data"
  5222 
  5260 
  5223     compressingStream ~~ zipFileStream ifTrue:[
  5261     super close.
  5224 	"close ZipStream"
       
  5225 	compressingStream close.
       
  5226     ].
       
  5227     compressingStream := nil.
       
  5228 
  5262 
  5229     zipEntry compressedSize:(zipFileStream position) - startDataPosition.
  5263     zipEntry compressedSize:(zipFileStream position) - startDataPosition.
  5230 
  5264 
  5231     "/ crc32 is always required (not as written in docu to be zero in case of uncompressed mode)
  5265     "/ crc32 is always required (not as written in docu to be zero in case of uncompressed mode)
  5232     zipEntry crc32:crc32.
  5266     zipEntry crc32:crc32.
  5233     zipEntry uncompressedSize:uncompressedDataSize.
  5267     zipEntry uncompressedSize:uncompressedDataSize.
  5234 
       
  5235     zipEntry rewriteCrcAndSizeTo:zipFileStream.
  5268     zipEntry rewriteCrcAndSizeTo:zipFileStream.
  5236 
  5269 
  5237     zipFileStream setToEnd.
  5270     zipFileStream setToEnd.
  5238 
  5271 
  5239     "Modified (comment): / 30-05-2017 / 19:02:28 / mawalch"
  5272     "Modified (comment): / 30-05-2017 / 19:02:28 / mawalch"
       
  5273     "Modified (format): / 11-06-2018 / 14:46:37 / Stefan Vogel"
  5240 ! !
  5274 ! !
  5241 
  5275 
  5242 !ZipArchive::ZipWriteStream methodsFor:'initialization'!
  5276 !ZipArchive::ZipWriteStream methodsFor:'initialization'!
  5243 
  5277 
  5244 zipFileStream:something zipEntry:aZipEntry
  5278 zipFileStream:something zipEntry:aZipEntry
  5245 
       
  5246     zipEntry := aZipEntry.
  5279     zipEntry := aZipEntry.
  5247     zipFileStream := something.
  5280     zipFileStream := something.
  5248     startDataPosition := zipFileStream position.
  5281     startDataPosition := zipFileStream position.
  5249     crc32 := 0.
  5282     crc32 := 0.
  5250     uncompressedDataSize := 0.
  5283     uncompressedDataSize := 0.
  5251 
  5284 
  5252     zipEntry compressionMethod == COMPRESSION_DEFLATED ifTrue:[
  5285     zipEntry compressionMethod == COMPRESSION_DEFLATED ifTrue:[
  5253 	compressingStream := ZipStream writeOpenAsZipStreamOn:zipFileStream suppressHeaderAndChecksum:true.
  5286         compressingStream := ZipStream writeOpenAsZipStreamOn:zipFileStream suppressHeaderAndChecksum:true.
  5254     ] ifFalse:[
  5287     ] ifFalse:[
  5255 	compressingStream := zipFileStream.
  5288         compressingStream := zipFileStream.
  5256     ].
  5289     ].
  5257 
  5290 
  5258     "Modified: / 19-11-2010 / 15:46:57 / cg"
  5291     "Modified: / 19-11-2010 / 15:46:57 / cg"
  5259     "Modified (format): / 30-05-2017 / 20:20:41 / mawalch"
  5292     "Modified (format): / 30-05-2017 / 20:20:41 / mawalch"
       
  5293     "Modified (format): / 11-06-2018 / 14:45:55 / Stefan Vogel"
  5260 ! !
  5294 ! !
  5261 
  5295 
  5262 !ZipArchive::ZipWriteStream methodsFor:'queries'!
  5296 !ZipArchive::ZipWriteStream methodsFor:'queries'!
  5263 
  5297 
  5264 isReadable
  5298 isReadable
  5278 !ZipArchive::ZipWriteStream methodsFor:'reading'!
  5312 !ZipArchive::ZipWriteStream methodsFor:'reading'!
  5279 
  5313 
  5280 contents
  5314 contents
  5281     "return the entire contents of the stream.
  5315     "return the entire contents of the stream.
  5282      For a readStream, that is the rest (i.e. upToEnd),
  5316      For a readStream, that is the rest (i.e. upToEnd),
  5283      for a writeStream, that is the collected data. As we do not know here,
  5317      for a writeStream, that is the collected data."
  5284      what we are, this is the responsibility of a subclass..."
       
  5285 
  5318 
  5286     self shouldNotImplement
  5319     self shouldNotImplement
       
  5320 
       
  5321     "Modified (comment): / 11-06-2018 / 14:47:59 / Stefan Vogel"
  5287 !
  5322 !
  5288 
  5323 
  5289 next
  5324 next
  5290     "return the next element of the stream
  5325     "return the next element of the stream"
  5291      - we do not know here how to do it, it must be redefined in subclass"
       
  5292 
  5326 
  5293     self shouldNotImplement
  5327     self shouldNotImplement
       
  5328 
       
  5329     "Modified (comment): / 11-06-2018 / 14:48:24 / Stefan Vogel"
  5294 !
  5330 !
  5295 
  5331 
  5296 peek
  5332 peek
  5297     "return the next element of the stream
  5333     "return the next element of the stream"
  5298      - we do not know here how to do it, it must be redefined in subclass"
       
  5299 
  5334 
  5300     self shouldNotImplement
  5335     self shouldNotImplement
       
  5336 
       
  5337     "Modified (comment): / 11-06-2018 / 14:48:32 / Stefan Vogel"
  5301 ! !
  5338 ! !
  5302 
  5339 
  5303 !ZipArchive::ZipWriteStream methodsFor:'writing'!
  5340 !ZipArchive::ZipWriteStream methodsFor:'writing'!
  5304 
  5341 
  5305 contents:aCollection
  5342 contents:aCollection