Report a bug
		
				If you spot a problem with this page, click here to create a Bugzilla issue.
		
			Improve this page
		
			Quickly fork, edit online, and submit a pull request for this page.
			Requires a signed-in GitHub account. This works well for small changes.
			If you'd like to make larger changes you may want to consider using
			a local clone.
		
	std.zip
Read/write data in the zip archive format.
 Makes use of the etc.c.zlib compression library.
Bugs: 
- Multi-disk zips not supported.
- Only Zip version 20 formats are supported.
- Only supports compression modes 0 (no compression) and 8 (deflate).
- Does not support encryption.
- Bugzilla 592
- Bugzilla 2137
Example
// Read existing zip file. import std.digest.crc, std.file, std.stdio, std.zip; void main(string[] args) { // read a zip file into memory auto zip = new ZipArchive(read(args[1])); writeln("Archive: ", args[1]); writefln("%-10s %-8s Name", "Length", "CRC-32"); // iterate over all zip members foreach (name, am; zip.directory) { // print some data about each member writefln("%10s %08x %s", am.expandedSize, am.crc32, name); assert(am.expandedData.length == 0); // decompress the archive member zip.expand(am); assert(am.expandedData.length == am.expandedSize); } } // Create and write new zip file. import std.file : write; import std.string : representation; void main() { char[] data = "Test data.\n".dup; // Create an ArchiveMember for the test file. ArchiveMember am = new ArchiveMember(); am.name = "test.txt"; am.expandedData(data.representation); // Create an archive and add the member. ZipArchive zip = new ZipArchive(); zip.addMember(am); // Build the archive void[] compressed_data = zip.build(); // Write to a file write("test.zip", compressed_data); }
License: 
Authors: 
Source std/zip.d
- classZipException: object.Exception;
- Thrown on error.
- enumCompressionMethod: ushort;
- Compression method used by ArchiveMember- none
- No compression, just archiving
- deflate
- Deflate algorithm. Use zlib library to compress
 
- classArchiveMember;
- A member of the ZipArchive.- stringname;
- Read/Write: Usually the file name of the archive member; it is used to index the archive directory for the member. Each member must have a unique name[]. Do not change without removing member from the directory first.
- ubyte[]extra;
- Read/Write: extra data for this member.
- stringcomment;
- Read/Write: comment associated with this member.
- ushortflags;
- Read/Write: normally set to 0
- ushortinternalAttributes;
- Read/Write
- const pure nothrow @nogc @property @safe ushortextractVersion();
- Read Only
- const pure nothrow @nogc @property @safe uintcrc32();
- Read Only: cyclic redundancy check (CRC) value
- const pure nothrow @nogc @property @safe uintcompressedSize();
- Read Only: size of data of member in compressed form.
- const pure nothrow @nogc @property @safe uintexpandedSize();
- Read Only: size of data of member in expanded form.
- const pure nothrow @nogc @property @safe ushortdiskNumber();
- Read Only: should be 0.
- pure nothrow @nogc @property @safe ubyte[]compressedData();
- Read Only: data of member in compressed form.
- pure nothrow @nogc @property @safe ubyte[]expandedData();
- Read data of member in uncompressed form.
- @property @safe voidexpandedData(ubyte[]ed);
- Write data of member in uncompressed form.
- @property @safe voidfileAttributes(uintattr);
- Set the OS specific file attributes, as obtained by std.file.getAttributes or std.file.DirEntry.attributes, for this archive member.
- const nothrow @nogc @property uintfileAttributes();
- Get the OS specific file attributes for the archive member.Returns:The file attributes or 0 if the file attributes were encoded for an incompatible OS (Windows vs. Posix).
- @property voidtime(SysTimetime);
 pure nothrow @nogc @property @safe voidtime(DosFileTimetime);
- Set the last modification time for this member.
- const pure nothrow @nogc @property @safe DosFileTimetime();
- Get the last modification time for this member.
- const pure nothrow @nogc @property @safe CompressionMethodcompressionMethod();
- Read compression method used for this memberSee Also:CompressionMethod
- pure @property @safe voidcompressionMethod(CompressionMethodcm);
- Write compression method used for this memberSee Also:CompressionMethod
- const pure nothrow @nogc @property @safe uintindex();
- The index of this archive member within the archive.
 
- classZipArchive;
- Object representing the entire archive. ZipArchives are collections of ArchiveMembers.- stringcomment;
- Read/Write: the archive comment. Must be less than 65536 bytes in length.
- pure nothrow @nogc @property @safe ubyte[]data();
- Read Only: array representing the entire contents of the archive.
- const pure nothrow @nogc @property @safe uintdiskNumber();
- Read Only: 0 since multi-disk zip archives are not supported.
- const pure nothrow @nogc @property @safe uintdiskStartDir();
- Read Only: 0 since multi-disk zip archives are not supported
- const pure nothrow @nogc @property @safe uintnumEntries();
 const pure nothrow @nogc @property @safe uinttotalEntries();
- Read Only: number of ArchiveMembers in the directory.
- const pure nothrow @nogc @property @safe boolisZip64();
- True when the archive is in Zip64 format.
- pure nothrow @nogc @property @safe voidisZip64(boolvalue);
- Set this to true to force building a Zip64 archive.
- pure nothrow @nogc @property @safe ArchiveMember[string]directory();
- Read Only: array indexed by the name of each member of the archive. All the members of the archive can be accessed with a foreach loop:Example ZipArchive archive = new ZipArchive(data); foreach (ArchiveMember am; archive.directory) { writefln("member name is '%s'", am.name); } 
- pure nothrow @nogc @safe this();
- Constructor to use when creating a new archive.
- @safe voidaddMember(ArchiveMemberde);
- Add de to the archive. The file is compressed on the fly.
- @safe voiddeleteMember(ArchiveMemberde);
- Delete de from the archive.
- pure @safe void[]build();
- Construct an archive out of the current members of the archive.Fills in the properties data[], diskNumber, diskStartDir, numEntries, totalEntries, and directory[]. For each ArchiveMember, fills in properties crc32, compressedSize, compressedData[].Returns:array representing the entire archive.
- this(void[]buffer);
- Constructor to use when reading an existing archive.Fills in the properties data[], diskNumber, diskStartDir, numEntries, totalEntries, comment[], and directory[]. For each ArchiveMember, fills in properties madeVersion, extractVersion, flags, compressionMethod, time, crc32, compressedSize, expandedSize, compressedData[], diskNumber, internalAttributes, externalAttributes, name[], extra[], comment[]. Use expand() to get the expanded data for each ArchiveMember.Parameters:void[] bufferthe entire contents of the archive. 
- ubyte[]expand(ArchiveMemberde);
- Decompress the contents of archive member de and return the expanded data.Fills in properties extractVersion, flags, compressionMethod, time, crc32, compressedSize, expandedSize, expandedData[], name[], extra[].
 
Copyright © 1999-2022 by the D Language Foundation | Page generated by
Ddoc on (no date time)