type
Zip
class Zip : Obj
Zip is used to read/write compressed zip files and streams. Zip may be used in three modes:
Zip.open
is used to read a random access file and provides access to the entire contents with the ability to read select entriesZip.read
is used to read a zip file from an input stream. Each entry is pulled off the stream usingreadNext
Zip.write
is used to write a zip file to an output stream. Each entry is written to the stream usingwriteNext
methods
close |
Close this zip file for reading and writing. |
---|---|
contents |
Return the contents of this zip as a map of Files. |
deflateInStream |
Construct a new deflate input stream which wraps the given input stream and inflates data written using the "deflate" compression format. |
deflateOutStream |
Construct a new deflate output stream which wraps the given output stream, and compresses data using the "deflate" compression format. |
file |
Get the underlying file or null if using streams. |
finish |
Finish writing the contents of this zip file, but leave the underlying OutStream open. |
gzipInStream |
Construct a new GZIP input stream which wraps the given input stream. |
gzipOutStream |
Construct a new GZIP output stream which wraps the given output stream. |
open |
Open the specified file as a zip file for reading. |
read |
Create a Zip used to read a zip file from the specified input stream. |
readEach |
Call the specified function for every entry in the zip. |
readNext |
Read the next entry in the zip. |
toStr |
If file is not null then return file.toStr, otherwise return a suitable string representation. |
unzipInto |
Static utility to unzip a zip file to the given directory. |
write |
Create a Zip used to write a zip file to the specified output stream. |
writeNext |
Append a new file to the end of this zip file and return an OutStream which may be used to write the file contents. |
Slot Details
close
Bool close()
Close this zip file for reading and writing. If this zip file is reading or writing an stream, then the underlying stream is also closed. This method is guaranteed to never throw an IOErr. Return true if the close was successful or false if the an error occurred.
contents
deflateInStream
deflateOutStream
static OutStream deflateOutStream(OutStream out, [Str:Obj?]? opts := null)
Construct a new deflate output stream which wraps the given output stream, and compresses data using the "deflate" compression format. Options:
- level: Int between 9 (best compression) to 0 (no compression)
- nowrap: Bool false to suppress defalate header and adler checksum
file
File? file()
Get the underlying file or null if using streams.
finish
Bool finish()
Finish writing the contents of this zip file, but leave the underlying OutStream open. This method is guaranteed to never throw an IOErr. Return true if the stream was finished successfully or false if the an error occurred. Throw UnsupportedErr if zip is not not writing to an output stream.
gzipInStream
gzipOutStream
open
read
readEach
readNext
File? readNext()
Read the next entry in the zip. Use the File's input stream to read the file contents. Some file meta-data such as size may not be available. Return null if at end of zip file. Throw UnsupportedErr if not reading from an input stream.
toStr
virtual override Str toStr()
If file is not null then return file.toStr, otherwise return a suitable string representation.
unzipInto
write
writeNext
OutStream writeNext(Uri path, DateTime modifyTime := DateTime.now(), [Str:Obj?]? opts := null)
Append a new file to the end of this zip file and return an OutStream which may be used to write the file contents. The Uri must not contain a query or fragment; it may optionally start with a slash. Closing the OutStream will close only this file entry - use Zip.close() when finished writing the entire zip file. Throw UnsupportedErr if zip is not writing to an output stream.
Next entry options:
- comment: Str entry comment
- crc: Int CRC-32 of the uncompressed data
- extra: Buf for extra bytes data field
- level: Int between 9 (best compression) to 0 (no compression)
- compressedSize: Int for compressed size of data
- uncompressedSize: Int for uncompressed size of data
NOTE: setting level to 0 sets method to STORE, else to DEFLATED.
Examples:
out := zip.writeNext(`/docs/test.txt`) out.writeLine("test") out.close