A single file or directory inside the archive.
Object representing the entire archive. ZipArchives are collections of ArchiveMembers.
Thrown on error.
Compression method used by ArchiveMember.
Example for reading an existing zip archive:
1 import std.stdio : writeln, writefln; 2 import std.file : read; 3 import std.zip; 4 5 void main(string[] args) 6 { 7 // read a zip file into memory 8 auto zip = new ZipArchive(read(args[1])); 9 10 // iterate over all zip members 11 writefln("%-10s %-8s Name", "Length", "CRC-32"); 12 foreach (name, am; zip.directory) 13 { 14 // print some data about each member 15 writefln("%10s %08x %s", am.expandedSize, am.crc32, name); 16 assert(am.expandedData.length == 0); 17 18 // decompress the archive member 19 zip.expand(am); 20 assert(am.expandedData.length == am.expandedSize); 21 } 22 }
Example for writing files into a zip archive:
1 import std.file : write; 2 import std.string : representation; 3 import std.zip; 4 5 void main() 6 { 7 // Create an ArchiveMembers for each file. 8 ArchiveMember file1 = new ArchiveMember(); 9 file1.name = "test1.txt"; 10 file1.expandedData("Test data.\n".dup.representation); 11 file1.compressionMethod = CompressionMethod.none; // don't compress 12 13 ArchiveMember file2 = new ArchiveMember(); 14 file2.name = "test2.txt"; 15 file2.expandedData("More test data.\n".dup.representation); 16 file2.compressionMethod = CompressionMethod.deflate; // compress 17 18 // Create an archive and add the member. 19 ZipArchive zip = new ZipArchive(); 20 21 // add ArchiveMembers 22 zip.addMember(file1); 23 zip.addMember(file2); 24 25 // Build the archive 26 void[] compressed_data = zip.build(); 27 28 // Write to a file 29 write("test.zip", compressed_data); 30 }
The current implementation mostly conforms to ISO/IEC 21320-1:2015, which means,
Additionally, archives are checked for malware attacks and rejected if detected. This includes
The current implementation makes use of the zlib compression library.
Usage:
There are two main ways of usage: Extracting files from a zip archive and storing files into a zip archive. These can be mixed though (e.g. read an archive, remove some files, add others and write the new archive).
Copyright The D Language Foundation 2000 - 2009.
Read and write data in the zip archive format.