Directories in zip
nobody
somebody at somewhere.com
Fri Dec 18 14:25:37 PST 2009
(I'm using D1)
Is it possible to create directories in a zip with std.zip? I couldn't find
any info about that.
So far I've only figured out how to read/write files. (code below)
Or should I be using something else entirely if I want to create archives?
---
module main;
import std.stdio: writefln;
import std.file: read, write;
import std.zip;
void main()
{
auto archive = new ZipArchive;
auto member = new ArchiveMember;
member.compressionMethod = 8; //0: none, 8: deflate
member.name = `hello.txt`;
member.expandedData = cast(ubyte[])`Hello`;
archive.addMember(member);
member = new ArchiveMember;
member.compressionMethod = 8;
member.name = `world.txt`;
member.expandedData = cast(ubyte[])`World!`;
archive.addMember(member);
auto data = archive.build();
write(`test.zip`,data);
auto text = read(`test.zip`);
auto archive2 = new ZipArchive(text);
foreach (ArchiveMember mem; archive2.directory)
{
archive2.expand(mem);
writefln(cast(char[])mem.expandedData);
}
}
---
More information about the Digitalmars-d-learn
mailing list