|
Class: ZipArchive
Object
|
+--ZipArchive
- Package:
- stx:libbasic2
- Category:
- System-Support-FileFormats
- Version:
- rev:
1.208
date: 2024/03/06 12:34:56
- user: cg
- file: ZipArchive.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
provides access to a zip archive.
Trailing slash.
Some implementations require a trailing slash in directory
names (such as the OpenOffice zip implementation). Others just
ignore external file attributes and indicate a directory entry
by adding a trailing slash (such as the Java zip implementation).
Since ZipArchive 1.98 a trailing slash is added for all directory
entries iff appendTrailingSlash instvar is set to true. By default
it is set to the value of DefaultAppendTrailingSlash which defaults
to true.
Setting appendTrailingSlash to false inhibits trailing slash
behavior.
Caveat:
the only compression methods (for now) are store and deflate.
[classvars:]
DefaultAppendTrailingSlash...a default value for appendTralingSlash instvar.
For details, see above
copyrightCOPYRIGHT (c) 1998 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
examples2add to new zip archive a entry which is located in memory using selector
addFile:'crcTest_resume_compressed.txt' withContents:
and real file contents from disk (uncompressed) identified by a readStream using selector
addFile:rdStreamFile fromStream:
[exBegin]
|zipwr testDirectory testFileWr rdStreamFile rdFileStream |
testDirectory := 'C:\Dokumente und Einstellungen\stefan\Eigene Dateien\tmp\'.
testFileWr := 'streamtest_uncompressed.zip'.
rdStreamFile := 'projects.zip'.
rdFileStream := ('C:\Dokumente und Einstellungen\stefan\Eigene Dateien\tmp\', rdStreamFile) asFilename readStream.
zipwr := ZipArchive newFileNamed:(testDirectory, testFileWr).
zipwr addFile:'crcTest_resume_compressed.txt' withContents: 'resume'.
zipwr addFile:rdStreamFile fromStream: rdFileStream.
zipwr close.
[exEnd]
read from zip archive a entry into memory using selector
extract:'crcTest_resume_compressed.txt'
and store an uncompressed archive entry to disk using a writeStream
extract: intoStream:
[exBegin]
|ziprd testDirectory testFileRd wrStreamFile wrFileStream data1|
testDirectory := 'C:\Dokumente und Einstellungen\stefan\Eigene Dateien\tmp\'.
testFileRd := 'streamtest_uncompressed.zip'.
wrStreamFile := 'test_projects.zip'.
ziprd := ZipArchive oldFileNamed:(testDirectory, testFileRd).
data1 := ziprd extract:'crcTest_resume_compressed.txt'.
wrFileStream := ('C:\Dokumente und Einstellungen\stefan\Eigene Dateien\tmp\', wrStreamFile) asFilename writeStream.
(ziprd extract:'projects.zip' intoStream: wrFileStream) ifFalse: [
self halt.
].
ziprd close.
wrFileStream close.
[exEnd]
add (compressed) to new zip archive a real file contents from disk e.g. a pdf
identified by a readStream
using selector
addFile: fromStream: compressMethod:
[exBegin]
|zipwr testDirectory testFileWr rdStreamFile rdFileStream|
testDirectory := 'C:\Dokumente und Einstellungen\stefan\Eigene Dateien\tmp\'.
testFileWr := 'streamtest_compressed.zip'.
rdStreamFile := 'test.pdf'.
rdFileStream := ('C:\Dokumente und Einstellungen\stefan\Eigene Dateien\tmp\', rdStreamFile) asFilename readStream.
zipwr := ZipArchive newFileNamed:(testDirectory, testFileWr).
zipwr addFileCompressed:rdStreamFile fromStream: rdFileStream.
zipwr close.
[exEnd]
read from zip archive a compressed entry e.g. a pdf and store the contents
to disk using a readStream
using selector
readStreamFor: rdStreamFile
[exBegin]
|ziprd testDirectory testFileRd wrStreamFile wrFileStream|
testDirectory := 'C:\Dokumente und Einstellungen\stefan\Eigene Dateien\tmp\'.
testFileRd := 'streamtest_compressed.zip'.
wrStreamFile := 'test_expecco.pdf'.
ziprd := ZipArchive oldFileNamed:(testDirectory, testFileRd).
wrFileStream := ('C:\Dokumente und Einstellungen\stefan\Eigene Dateien\tmp\', wrStreamFile) asFilename writeStream.
(ziprd extract:'test.pdf' intoStream: wrFileStream) ifFalse: [
self halt.
].
ziprd close.
wrFileStream close.
[exEnd]
examples3add to new zip archive recursive the contents of a directory (uncompressed)
addArchiveDirectory: fromOsDirectory:
[exBegin]
|zipwr testDirectory testFileWr zipDirectory |
testDirectory := 'C:\Dokumente und Einstellungen\stefan\Eigene Dateien\tmp\'.
testFileWr := 'zipDirectoryTest.zip'.
zipDirectory := 'abc'.
zipwr := ZipArchive newFileNamed:(testDirectory, testFileWr).
zipwr addArchiveDirectory: 'attachments' fromOsDirectory: (testDirectory,zipDirectory).
zipwr close.
[exEnd]
read from zip archive all entries which are stored in an archive directory (uncompressed)
and store all those entries in a directory on the file system
restoreOsDirectory: fromArchiveDirectory:
[exBegin]
|ziprd testDirectory testFileRd zipDirectory|
testDirectory := 'C:\Dokumente und Einstellungen\stefan\Eigene Dateien\tmp\'.
testFileRd := 'zipDirectoryTest.zip'.
zipDirectory := 'xxx'.
ziprd := ZipArchive oldFileNamed:(testDirectory, testFileRd).
ziprd restoreOsDirectory: (testDirectory,zipDirectory) fromArchiveDirectory: 'attachments'.
ziprd close.
[exEnd]
add to new zip archive recursive the contents of a directory (compressed)
addArchiveDirectoryCompressed: fromOsDirectory:
[exBegin]
|zipwr testDirectory testFileWr zipDirectory |
testDirectory := 'C:\Dokumente und Einstellungen\stefan\Eigene Dateien\tmp\'.
testFileWr := 'zipDirectoryTestCompressed.zip'.
zipDirectory := 'abc'.
zipwr := ZipArchive newFileNamed:(testDirectory, testFileWr).
zipwr addArchiveDirectoryCompressed: 'attachments' fromOsDirectory: (testDirectory,zipDirectory).
zipwr close.
[exEnd]
read from zip archive all entries which are stored in an archive directory (compressed)
and store all those entries in a directory on the file system
restoreOsDirectory: fromArchiveDirectory:
[exBegin]
|ziprd testDirectory testFileRd zipDirectory|
testDirectory := 'C:\Dokumente und Einstellungen\stefan\Eigene Dateien\tmp\'.
testFileRd := 'zipDirectoryTestCompressed.zip'.
zipDirectory := 'xxx-compressed'.
ziprd := ZipArchive oldFileNamed:(testDirectory, testFileRd).
ziprd restoreOsDirectory: (testDirectory,zipDirectory) fromArchiveDirectory: 'attachments'.
ziprd close.
[exEnd]
examples4can we handle zip42.zip (a zip bomb)?
Yes, kind of:
because I will only extract one level of files,
there is no danger of a recursive extract.
[exBegin]
|badFile ziprd outDir|
badFile := Filename downloadsDirectory / '42.zip'.
(outDir := Filename downloadsDirectory / '42') makeDirectory.
ziprd := ZipArchive oldFileNamed:badFile.
ziprd restoreOsDirectory:outDir fromArchiveDirectory: '/'.
ziprd close.
FileBrowser default openOn:outDir
[exEnd]
fileFormatDescriptionFile: APPNOTE.TXT - .ZIP File Format Specification
Signal constants
-
unsupportedZipFileFormatErrorSignal
-
-
zipFileFormatErrorSignal
-
accessing-defaults
-
defaultAppendTrailingSlash
-
Returns the default trailing slash behavior. For details
see the class documentation
-
defaultAppendTrailingSlash: aBoolean
-
Sets the default trailing slash behavior. For details
see the class documentation
-
zipFileCachingTime: seconds
-
by default, zip files are cached for some time,
in case they are reconsulted soon.
The default time is 60s, but can be changed by this setter
class initialization
-
initialize
-
self initialize
cleanup
-
flush
-
forget about cached zipArchives
Usage example(s):
-
installFlushBlock
-
forget about cached zipArchives
Usage example(s):
-
lowSpaceCleanup
-
forget about cached zipArchives
Usage example(s):
constants
-
COMPRESSION_DEFLATED
-
please use compressionDeflated instead (Squeak compat.)
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
COMPR_DEFLATED
-
please use compressionDeflated instead (Squeak compat.)
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
LREC_SIZE
-
-
centralDirectoryMinimumSize
-
-
compressionDeflated
-
same as COMPRESSION_DEFLATED - squeak compatibility
-
compressionStored
-
same as COMPRESSION_STORED - squeak compatibility
-
streamBufferSize
-
chunk size when reading from/writing to a Stream
instance creation
-
appendFileNamed: aFilename
-
return a zipArchive open on a filename;
if the file exists, items are added;
if not, it is created anew.
-
new
-
(comment from inherited method)
return an instance of myself without indexed variables
-
newFileNamed: aFilename
-
return a zipArchive open on a new created filename
-
oldFileNamed: aFilename
-
return a zipArchive open on aFilename
-
oldFileNamed: aFilename startOfArchive: startOfArchive endOfArchive: endOfArchive
-
return a zipArchive open on aFilename
-
readingFile: aFilename do: aBlock
-
Open a instance on aFilename, evaluate aBlock, passing the archive,
and return the block's value.
Ensures that the archive is closed.
-
readingFrom: aPositionableStream
-
open an existing Zip archive - read data from aPositionableStream
-
writingTo: aPositionableStream
-
open an new Zip archive - write data to aPositionableStream
private
-
validZipFileNameFrom: zipFileName
-
construct a valid zip filename
Usage example(s):
ZipArchive new validZipFileNameFrom:'hello//world'
ZipArchive new validZipFileNameFrom:'hello\\world'
ZipArchive new validZipFileNameFrom:'hello\/world'
ZipArchive new validZipFileNameFrom:'hello/\world'
ZipArchive new validZipFileNameFrom:'hello/\world/aaa bbb/ccc'
|
private - decompression
-
decode: rawBytes method: compressionMethod size: uncompressedSize asString: asStringBoolean
-
decode rawBytes into a byteArray or string.
Answer the decoded data or raise an Error.
queries
-
isZipArchive: aFilename
-
answer true, if aFilename references a Zip archive
utilities
-
dateToZipFileDate: aDate
-
data in msdos format
-
timeToZipFileTime: aTime
-
time in msdos format
-
zipFileDateToDate: zipDate
-
data in msdos format
Usage example(s):
self zipFileDateToDate:0
self zipFileDateToDate:0x354b => 11-10-2006
self dateToZipFileDate:(Date newDay:11 month:11 year:2006) => 13675 (= 0x354b)
File modification date stored in standard MS-DOS format:
Bits 00-04: day
Bits 05-08: month
Bits 09-15: years from 1980
|
-
zipFileTimeToTime: zipTime
-
time in msdos format
Usage example(s):
self zipFileTimeToTime:0x7d1c => 15:40:56
self timeToZipFileTime:(Time hours:15 minutes:40 seconds:56) => 32028 (= 0x7d1c)
File modification time stored in standard MS-DOS format:
Bits 00-04: seconds divided by 2
Bits 05-10: minute
Bits 11-15: hour
|
-
zipFileTimestampFromDate: zipDate time: zipTime
-
date in msdos format
Usage example(s):
self zipFileTimestampFromDate:0x354b time:0x7d1c
=> 11-10-2006 15:40:56
self timeToZipFileTime:(Time hours:15 minutes:40 seconds:56) => 32028 (= 0x7d1c)
self dateToZipFileDate:(Date newDay:11 month:11 year:2006) => 13675 (= 0x354b)
|
Compatibility-Squeak
-
binaryContentsOf: fileName
-
-
contentsOf: fileName
( an extension from the stx:libcompat package )
-
-
desiredCompressionMethod: aCompressionMethod
-
for now: ignored
-
testUTF8
( an extension from the stx:libcompat package )
-
accessing
-
appendTrailingSlash
-
Returns default trailing slash behavior, For details,
see class documentation
-
appendTrailingSlash: aBoolean
-
Sets trailing slash behavior. If true, all directory entries
will have a trailing slash in its nama. For details, see class
documentation
-
entries
-
return a collection of fileName entries
-
file
-
-
fileSize
-
-
memberNamed: aFilename
-
-
members
-
return a collection of members
-
membersMatching: aFileMatchPattern
-
return a collection of members which match aFileMatchPattern
-
name
-
return the (file-)name of this zipArchive
-
numberOfEntries
-
return the number of entries in the archive
-
pathName
-
FileStream compatibility: answer the name of the underlying file - a String
-
rawStream
-
-
setArchiveStartPosition: aStartposition endPosition: anEndPosition
-
-
signatureInformation
-
for compatibility with SignedZipArchive
-
size
-
Modified (format): / 17-02-2017 / 22:30:50 / stefan
-
zipMembersByName
-
accessing-misc
-
objectAttributes
-
return a Collection of attributes - nil if there is none.
-
objectAttributes: aDictionary
-
(comment from inherited method)
set the collection of attributes.
The default implementation here uses a global Dictionary to store
attributes which may be too slow for high frequency change&update.
Therefore, some classes may redefine this for better performance.
comparing
-
= aZipArchiveToCompare
-
open both archives
- check file size
- check number of archive members
- perform a binary compare of the archives.
-
hash
-
(comment from inherited method)
return an Integer useful as a hash key for the receiver.
This hash should return same values for objects with same
contents (i.e. use this to hash on structure)
error raising
-
error: anErrorString
-
redefined, to raise ZipFileFormatErrorSignal
open & close
-
close
-
-
closePrepareForReopen
-
close the underlying OS resources (stream),
but keep enough information to allow reopening later (i.e. the archive name)
-
flush
-
finish the zip archive, but do not close the underlying stream
-
name: filenameOrString mode: readOrWriteOrAppendModeSymbol
-
open read or writestream on archiveFileName.
readOrWriteOrAppendModeSymbol is either #read, #write or #append.
Usage example(s):
self new name:'/tmp/zip.zip' mode:#write
self new name:'/tmp/zip.zip' asFilename mode:#write
|
-
readFrom: aPositionableStreamOrFilenameString
-
initialize the archive to read from aPositionableStream,
or from the file by that name (pharo compatibility)
Obsolete - backward compatibility.
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
readingFrom: aPositionableStream
-
initialize the archive to read from aPositionableStream
-
reopenForReading
-
-
writingTo: aPositionableStream
-
initialize the archive to write to aPositionableStream
printing
-
printOn: aStream
-
(comment from inherited method)
append a user printed representation of the receiver to aStream.
The format is suitable for a human - not meant to be read back.
The default here is to output the receiver's class name.
BUT: this method is heavily redefined for objects which
can print prettier.
private
-
closeFile
-
backward compatibility
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
dataStartOf: zipEntry
-
fetch the absolute start address of the data of a given zipEntry.
Note: extra field and extra field length may be different from that in
the central directory entry. Sow e have to fetch the local header.
-
initialize
-
(comment from inherited method)
just to ignore initialize to objects which do not need it
-
openFile
-
-
setDefaultArchiveBounds
-
set start and end of archive if it is nil. That means no bounds have been defined
before. In that case the archive is the complete file.
private - directory stuff
-
addCentralZipDirectory
-
ensure that the file position is at end
-
addMember: zmemb
-
add a zipMember
-
checkZipArchive
-
check if my file is really a zip archive. answer true or false.
-
checkZipArchive: archiveFileName
-
-
findMember: name
-
find a zipMember by name
-
findMemberAllowForMissingTrailingSlash: name
-
find a zipMember by name. Allow for missing trailing slash for directories.
This method is currently used by JavaVM
-
findMemberForWhich: aOneArgBlock
-
find a zipMember by condition
-
readDirectory
-
read the zip directory into a linked-list of zipMembers
-
searchForEndOfCentralDirectorySignature
-
read the zip directory into a linked-list of zipMembers
-
zipMembersDo: aBlock
-
evaluate aBlock for all zipMembers
queries
-
isValidFile: path
-
Return true, if the receiver contains given file. false otherwise.
-
isValidPath: anArchivePathName
-
reading
-
extract: fileName
-
extract an entry identified by fileName as a byteArray;
nil on errors
-
extract: fileName asString: asStringBoolean
-
extract an entry identified by fileName as a byteArray or string;
return the extracted string or byteArray, nil on errors
-
nextBytes: nBytesToRead of: zmember startingAt: pos into: aByteArray startingAt: writeOffset
-
-
restoreOsDirectory: osDirectoryName fromArchiveDirectory: archiveDirectoryName
-
extracts all files from an archiveDirectory (that is the dir name inside the zip)
into a folder (that is a folder on the disk).
Abswer the number of extracted plain files.
-
withPositionAndMemberFor: fileName do: aBlock
-
return nil, if the file is not in the archive,
or the value from aBlock if it is
-
withPositionAndMemberFor: fileName do: aBlock onError: failBlock
-
return the value from failBlock, if the archive cannot be read
or the file is not in the archive,
or the value from aBlock if it is
reading - stream
-
extract: fileNameInZipArchive intoFile: aFilename restoreModificationTime: restoreModificationTime
-
extract an entry identified by fileNameInZipArchive into aFilename.
If restoreModificationTime is set to true restore the modificationTime of aFilename
to the time as stored in the archive.
Return nil if failed, number of bytes read on success
-
extract: fileName intoStream: aWriteStream
-
extract an entry identified by filename into aWriteStream.
Return nil if failed, number of bytes read on success
-
extract: fileName intoStream: aWriteStream restoreModificationTime: restoreModificationTime
-
extract an entry identified by filename into aWriteStream.
If restoreModificationTime is set to true and aWriteStream is a FileStream,
restore the modificationTime of the destination file to the time as stored in the archive.
Return nil if failed, number of bytes read on success.
-
extract: fileName toStream: outStream
-
marked as obsolete by Stefan Vogel at 13-Jul-2023
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
readStreamFor: nameOfFileInArchive
-
open a stream on archive contents identified by nameOfFileInArchive
-
readStreamForMember: zipEntry
-
open a stream on a member entry
-
reopenAndExtract: fileName intoStream: aWriteStream
-
extract an entry identified by filename into aWriteStream
writing
-
addArchiveDirectory: archiveDirectoryName fromOsDirectory: osDirectoryName
-
-
addArchiveDirectory: archiveDirectoryName fromOsDirectory: osDirectoryName compressMethod: theCompressMethod
-
do not create directories (isDirectory = true) - they are not compatible between operating systems
-
addArchiveDirectoryCompressed: archiveDirectoryName fromOsDirectory: osDirectoryName
-
-
addDirectory: dirNameInZip
-
do not create directories (isDirectory = true) - they are not compatible between operating systems
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
addFile: aFileName as: fileNameInZip
-
-
addFile: fileNameInZip fromStream: aStream
-
-
addFile: fileNameInZip fromStream: aStream compressMethod: theCompressMethodArg
-
-
addFile: fileNameInZip fromStream: aStream compressMethod: theCompressMethodArg asDirectory: isDirectory
-
Create a new entry named fileNameInZip in the archive.
Contents is read from aStream up to the end.
Do not create directories (isDirectory = true) - they are not compatible between operating systems
-
addFile: fileNameInZip fromStream: aStream compressMethod: theCompressMethodArg asDirectory: isDirectory preserveModificationTime: preserveModificationTime
-
Create a new entry named fileNameInZip in the archive.
Contents is read from aStream up to the end.
Do not create directories (isDirectory = true) - they are not compatible between operating systems.
If preserveModificationTime is set to true, set the modificationTime (time and date) stored in the
archive to the modificationTime of the file aStream originates from (only for FileStreams);
else the modificationTime will be set to now.
-
addFile: fileNameInZip withContents: data
-
-
addFile: fileNameInZip withContents: data compressMethod: compressMethod
-
-
addFile: fileNameInZip withContents: data compressMethod: theCompressMethodArg asDirectory: isDirectory
-
do not create directories (isDirectory = true) - they are not compatible between operating systems
-
addFileCompressed: fileNameInZip fromStream: aStream
-
-
addFileCompressed: fileNameInZip fromStream: aStream preserveModificationTime: preserveModificationTime
-
-
addFileCompressed: fileNameInZip withContents: data
-
-
addString: aString as: fileNameInZip
-
self addFile:fileNameInZip fromStream:(aString readStream)
-
basicAddFile: aFileName withContents: data compressMethod: theCompressMethodArg asDirectory: isDirectory
-
do not create directories (isDirectory = true) - they are not compatible between operating systems
writing - stream
-
compressedWriteStreamFor: nameOfFileInArchive
-
create new entry in central directory
-
writeStreamFor: nameOfFileInArchive compressMethod: theCompressMethodArg
-
create new entry in central directory
AbstractZipStream
ZipCentralDirectory
ZipMember
ZipReadStream
ZipWriteStream
|zip bytes|
'fooZZZZ.zip' asFilename remove.
zip := ZipArchive newFileNamed:'fooZZZZ.zip'.
zip addFileCompressed:'bar' withContents:'hello world'.
zip close.
|
|zip bytes|
zip := ZipArchive oldFileNamed:'fooZZZZ.zip'.
bytes := zip extract:'bar'.
zip close.
'fooZZZZ.zip' asFilename remove.
bytes
|
|zip bytes|
zip := ZipArchive oldFileNamed:'source/stx/libbasic2.zip'.
zip entries do:[:entry |
Transcript showCR:entry
].
zip close.
|
|zip bytes|
zip := ZipArchive oldFileNamed:'source/stx/libbasic2.zip'.
bytes := zip extract:'TwoByteStr.st'.
zip close.
Transcript showCR:(bytes asString).
|
compatibility write check with winzip (compressed with deflate)
|zipwr testDirectory testFileWr|
testDirectory := 'C:\Dokumente und Einstellungen\stefan\Eigene Dateien\tmp\'.
testFileWr := 'crcTest_resume_compressed.zip'.
zipwr := ZipArchive newFileNamed:(testDirectory, testFileWr).
zipwr addFile:'crcTest_resume_compressed.txt' withContents: 'resume'.
zipwr close.
|
compatibility read check with winzip (compressed with deflate)
|ziprd testDirectory testFileRd contents|
testDirectory := 'C:\Dokumente und Einstellungen\stefan\Eigene Dateien\tmp\'.
testFileRd := 'crcTest_resume_compressed.zip'.
ziprd := ZipArchive oldFileNamed:(testDirectory, testFileRd).
contents := ziprd extract: ziprd entries first.
contents inspect.
ziprd close.
|
compatibility write check with winzip (uncompressed)
|zipwr testDirectory testFileWr|
testDirectory := 'C:\Dokumente und Einstellungen\stefan\Eigene Dateien\tmp\'.
testFileWr := 'crcTest_resume_uncompressed.zip'.
zipwr := ZipArchive newFileNamed:(testDirectory, testFileWr).
zipwr addFile:'crcTest_resume_uncompressed.txt'
withContents:'resume'
compressMethod:0
asDirectory:false.
zipwr close.
|
compatibility read check with winzip (uncompressed)
|ziprd testDirectory testFileRd contents|
testDirectory := 'C:\Dokumente und Einstellungen\stefan\Eigene Dateien\tmp\'.
testFileRd := 'crcTest_resume_uncompressed.zip'.
ziprd := ZipArchive oldFileNamed:(testDirectory, testFileRd).
contents := ziprd extract: ziprd entries first.
contents inspect.
ziprd close.
|
read an archive with files and/or directories, fetch the entries
and create a new archive with the same content
|ziprd zipwr entryDict testDirectory testFileRd testFileWr|
testDirectory := 'C:\Dokumente und Einstellungen\stefan\Eigene Dateien\tmp\'.
testFileRd := 'projects.zip'.
testFileWr := 'projects_expecco_test.zip'.
ziprd := ZipArchive oldFileNamed:(testDirectory, testFileRd).
entryDict := Dictionary new.
ziprd entries do: [:aFileName|
entryDict at:aFileName put:(ziprd extract: aFileName) asString.
].
ziprd close.
zipwr := ZipArchive newFileNamed:(testDirectory, testFileWr).
entryDict keysAndValuesDo: [:key :value|
(value size == 0) ifTrue: [
zipwr addDirectory:key.
] ifFalse: [
zipwr addFile:key withContents:value
].
].
zipwr close.
|
|zipwr ziprd testDirectory testFileWr testFileRd zs|
testDirectory := 'C:\Dokumente und Einstellungen\stefan\Eigene Dateien\tmp\'.
testFileWr := 'crcTest_resume_compressed.zip'.
zipwr := ZipArchive newFileNamed:(testDirectory, testFileWr).
zipwr addFile:'crcTest_resume_compressed.txt' withContents: 'Das ist ein test, das ist ein test, das ist ein test'.
zipwr close.
testFileRd := 'crcTest_resume_compressed.zip'.
ziprd := ZipArchive oldFileNamed:(testDirectory, testFileRd).
zs := ziprd readStreamFor: 'crcTest_resume_compressed.txt'.
zs inspect.
ziprd close.
|
|zipwr ziprd testDirectory testFileWr testFileRd rs result|
testDirectory := 'C:\Dokumente und Einstellungen\stefan\Eigene Dateien\tmp\'.
testFileWr := 'readStreamTest_HelloWorld.zip'.
zipwr := ZipArchive newFileNamed:(testDirectory, testFileWr).
zipwr addFile:'readStreamTest_HelloWorld.txt' withContents: 'Hello World!' compressed: false.
zipwr close.
testFileRd := 'readStreamTest_HelloWorld.zip'.
ziprd := ZipArchive oldFileNamed:(testDirectory, testFileRd).
rs := ziprd readStreamFor: 'readStreamTest_HelloWorld.txt'.
result := ''.
[ rs atEnd ] whileFalse: [
result := result, (rs nextAvailable:5).
].
result inspect.
rs close.
ziprd close.
|
read an archive with files and/or directories and/or zipArchives,
fetch the entries (also from the include zip archives)
and create a new archive
|ziprd zipwr entryDict testDirectory testFileRd testFileWr zipRdSub1 zipRdSub2|
testDirectory := 'C:\Dokumente und Einstellungen\stefan\Eigene Dateien\tmp\'.
testFileRd := 'ZipInZipFileTest.zip'.
testFileWr := 'ZipInZipFileTest_generated.zip'.
ziprd := ZipArchive oldFileNamed:(testDirectory, testFileRd).
entryDict := Dictionary new.
ziprd entries do: [:aFileName|
Transcript showCR: 'processing in top: ', aFileName.
(aFileName endsWith:'.zip') ifTrue: [
zipRdSub1 := ziprd extractArchive: aFileName.
zipRdSub1 entries do: [:aFileName1|
Transcript showCR: 'processing in sub 1: ', aFileName1.
(aFileName1 endsWith:'.zip') ifTrue: [
zipRdSub2 := zipRdSub1 extractArchive: aFileName1.
zipRdSub2 entries do: [:aFileName2|
Transcript showCR: 'processing in sub 2: ', aFileName2.
(aFileName2 endsWith:'.zip') ifTrue: [
self halt.
] ifFalse: [
entryDict at:aFileName2 put:(zipRdSub2 extract: aFileName2) asString.
].
].
zipRdSub2 close.
] ifFalse: [
entryDict at:aFileName1 put:(zipRdSub1 extract: aFileName1) asString.
].
].
zipRdSub1 close.
] ifFalse: [
entryDict at:aFileName put:(ziprd extract: aFileName) asString.
].
].
ziprd close.
zipwr := ZipArchive newFileNamed:(testDirectory, testFileWr).
entryDict keysAndValuesDo: [:key :value|
(value size == 0) ifTrue: [
zipwr addDirectory:key.
] ifFalse: [
zipwr addFile:key withContents:value
].
].
zipwr close.
|
|