tango.io.compress.Zip

License:

BSD style: see license.txt

Version:

Initial release: December 2007

Author:

Daniel Keep
struct LocalFileHeaderData [private] #
struct FileHeaderData [private] #
struct EndOfCDRecordData [private] #
enum Method [public] #
This enumeration denotes the kind of compression used on a file.
Store #
No compression should be used.
Deflate #
Deflate compression.
Unsupported #
This is a special value used for unsupported or unrecognised compression methods. This value is only used internally.
interface ZipReader #
interface ZipWriter #
class ZipBlockReader : ZipReader #
The ZipBlockReader class is used to parse a Zip archive. It exposes the contents of the archive via an iteration interface. For instance, to loop over all files in an archive, one can use either
1
2
foreach( entry ; reader )
    ...

Or

1
2
3
4
5
while( reader.more )
{
    auto entry = reader.get;
    ...
}

See the ZipEntry class for more information on the contents of entries.

Note that this class can only be used with input sources which can be freely seeked. Also note that you may open a ZipEntry instance produced by this reader at any time until the ZipReader that created it is closed.

this(char[] path) #
Creates a ZipBlockReader using the specified file on the local filesystem.
this(InputStream source) #
Creates a ZipBlockReader using the provided InputStream. Please note that this InputStream must be attached to a conduit implementing the IConduit.Seek interface.
void close() #
Closes the reader, and releases all resources. After this operation, all ZipEntry instances created by this ZipReader are invalid and should not be used.
bool more() #
Returns true if and only if there are additional files in the archive which have not been read via the get method. This returns true before the first call to get (assuming the opened archive is non-empty), and false after the last file has been accessed.
ZipEntry get() #
ZipEntry get(ZipEntry reuse) #
Retrieves the next file from the archive. Note that although this does perform IO operations, it will not read the contents of the file.
The optional reuse argument can be used to instruct the reader to reuse an existing ZipEntry instance. If passed a null reference, it will create a new ZipEntry instance.
int opApply(int delegate(ref ZipEntry) dg) #
This is used to iterate over the contents of an archive using a foreach loop. Please note that the iteration will reuse the ZipEntry instance passed to your loop. If you wish to keep the instance and re-use it later, you must use the dup member to create a copy.
class ZipBlockWriter : ZipWriter #
The ZipBlockWriter class is used to create a Zip archive. It uses a writing iterator interface.
Note that this class can only be used with output streams which can be freely seeked.
this(char[] path) #
Creates a ZipBlockWriter using the specified file on the local filesystem.
this(OutputStream output) #
Creates a ZipBlockWriter using the provided OutputStream. Please note that this OutputStream must be attached to a conduit implementing the IConduit.Seek interface.
void finish() #
Finalises the archive, writes out the central directory, and closes the output stream.
void putFile(ZipEntryInfo info, char[] path) #
Adds a file from the local filesystem to the archive.
void putStream(ZipEntryInfo info, InputStream source) #
Adds a file using the contents of the given InputStream to the archive.
void putEntry(ZipEntryInfo info, ZipEntry entry) #
Transfers a file from another archive into this archive. Note that this method will not perform any compression: whatever compression was applied to the file originally will be preserved.
void putData(ZipEntryInfo info, void[] data) #
Adds a file using the contents of the given array to the archive.
Method method() #
Method method(Method v) #
This property allows you to control what compression method should be used for files being added to the archive.
class ZipEntry #
This class is used to represent a single entry in an archive. Specifically, it combines meta-data about the file (see the info field) along with the two basic operations on an entry: open and verify.
ZipEntryInfo info #
Header information on the file. See the ZipEntryInfo structure for more information.
uint size() #
Size (in bytes) of the file's uncompressed contents.
InputStream open() #
Opens a stream for reading from the file. The contents of this stream represent the decompressed contents of the file stored in the archive.
You should not assume that the returned stream is seekable.

Note that the returned stream may be safely closed without affecting the underlying archive stream.

If the file has not yet been verified, then the stream will be checked as you read from it. When the stream is either exhausted or closed, then the integrity of the file's data will be checked. This means that if the file is corrupt, an exception will be thrown only after you have finished reading from the stream. If you wish to make sure the data is valid before you read from the file, call the verify method.

void verify() #
Verifies the contents of this file by computing the CRC32 checksum, and comparing it against the stored one. Throws an exception if the checksums do not match.
Not valid on streamed Zip archives.
ZipEntry dup() #
Creates a new, independent copy of this instance.
struct ZipEntryInfo #
This structure contains various pieces of meta-data on a file. The contents of this structure may be safely mutated.
This structure is also used to specify meta-data about a file when adding it to an archive.
char[] name #
Full path and file name of this file.
Time modified #
Modification timestamp. If this is left uninitialised when passed to a ZipWriter, it will be reset to the current system time.
char[] comment #
Comment on the file.
class ZipException : Exception #
This is the base class from which all exceptions generated by this module derive from.
class ZipChecksumException : ZipException #
This exception is thrown if a ZipReader detects that a file's contents do not match the stored checksum.
class ZipExhaustedException : ZipException #
This exception is thrown if you call get reader method when there are no more files in the archive.
class ZipNotSupportedException : ZipException #
This exception is thrown if you attempt to read an archive that uses features not supported by the reader.
void createArchive(char[] archive, Method method, char[][] files...) #
class ZipEntryVerifier : InputStream [private] #
void readExact(InputStream s, void[] dst) [private] #
void swapAll(T)(ref T data) [private] #
char[][] cp437_to_utf8_map_low [private, const] #
void dosToTime(ushort dostime, ushort dosdate, out Time time) [private] #
class CounterInput : InputStream [private] #
class CounterOutput : OutputStream [private] #

Copyright:

Copyright © 2007 Daniel Keep. All rights reserved.

License:

BSD style: see license.txt

Version:

Prerelease

Author:

Daniel Keep

The counter stream classes are used to keep track of how many bytes flow through a stream.

To use them, simply wrap it around an existing stream. The number of bytes that have flowed through the wrapped stream may be accessed using the count member.

this(InputStream input) #
long count() #
class SliceSeekInputStream : InputStream [private] #

Copyright:

Copyright © 2007 Daniel Keep. All rights reserved.

License:

BSD style: see license.txt

Version:

Prerelease

Author:

Daniel Keep

This stream can be used to provide stream-based access to a subset of another stream. It is akin to slicing an array.

This stream fully supports seeking, and as such requires that the underlying stream also support seeking.

this(InputStream source, long begin, long length) #
Create a new slice stream from the given source, covering the content starting at position begin, for length bytes.
class SliceInputStream : InputStream [private] #
This stream can be used to provide stream-based access to a subset of another stream. It is akin to slicing an array.
this(InputStream source, long length) #
Create a new slice stream from the given source, covering the content starting at the current seek position for length bytes.
class SliceSeekOutputStream : OutputStream [private] #
This stream can be used to provide stream-based access to a subset of another stream. It is akin to slicing an array.
This stream fully supports seeking, and as such requires that the underlying stream also support seeking.
this(OutputStream source, long begin, long length) #
Create a new slice stream from the given source, covering the content starting at position begin, for length bytes.
class WrapSeekInputStream : InputStream [private] #

Copyright:

Copyright © 2007 Daniel Keep. All rights reserved.

License:

BSD style: see license.txt

Version:

Prerelease

Author:

Daniel Keep

This stream can be used to provide access to another stream. Its distinguishing feature is that users cannot close the underlying stream.

This stream fully supports seeking, and as such requires that the underlying stream also support seeking.

this(InputStream source) #
this(InputStream source, long position) #
Create a new wrap stream from the given source.
class WrapSeekOutputStream : OutputStream [private] #
This stream can be used to provide access to another stream. Its distinguishing feature is that the users cannot close the underlying stream.
This stream fully supports seeking, and as such requires that the underlying stream also support seeking.
this(OutputStream source) #
this(OutputStream source, long position) #
Create a new wrap stream from the given source.