显然,新文档没有显示此模块的用法。我读的来源和整理出来,这是为了做到这一点:
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文件。