顯然,新文檔沒有顯示此模塊的用法。我讀的來源和整理出來,這是爲了做到這一點:
import std.file: write;
import std.string: representation;
import std.zip: ArchiveMember, ZipArchive;
void main()
{
char[] contents = "This is my test data.\n".dup;
// Create the archive.
auto zip = new ZipArchive();
// Create the archive entry
ArchiveMember ae = new ArchiveMember();
ae.name = "test.txt";
ae.expandedData(contents.representation);
// Add to the entry to the archive.
zip.addMember(ae);
// Build the archive.
void[] compressed_data = zip.build();
// Write the archive data to a file.
write("test.zip", compressed_data);
}
而且它的工作原理:
$ ./addzip
$ unzip test.zip
Archive: test.zip
extracting: test.txt
$ cat test.txt
This is my test data.
火衛一的下一個版本將具有文檔中的例子,說明如何閱讀和編寫zip文件。