View source code
Display the source code in std/zip.d from which this page was generated on github.
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 local clone.


Read/write data in the zip archive format. Makes use of the etc.c.zlib compression library.


  • 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


// Read existing zip file.
import std.digest.crc, std.file, std.stdio,;

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;
        // print some data about each member
        writefln("%10s  %08x  %s", am.expandedSize, am.crc32, name);
        assert(am.expandedData.length == 0);
        // decompress the archive member
        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(); = "test.txt";
    // Create an archive and add the member.
    ZipArchive zip = new ZipArchive();
    // Build the archive
    void[] compressed_data =;
    // Write to a file
    write("", compressed_data);


ArchiveMember A member of the ZipArchive.
ZipArchive Object representing the entire archive. ZipArchives are collections of ArchiveMembers.
ZipException Thrown on error.


CompressionMethod Compression method used by ArchiveMember


Walter Bright


Boost License 1.0.