-
-
Notifications
You must be signed in to change notification settings - Fork 593
/
testzip.d
111 lines (91 loc) · 2.63 KB
/
testzip.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// PERMUTE_ARGS:
// EXECUTE_ARGS: runnable/extra-files/testzip.zip ${RESULTS_DIR}/runnable/testzip-out.zip
// POST_SCRIPT: runnable/extra-files/testzip-postscript.sh
import core.stdc.stdio;
import std.conv;
import std.stdio;
import std.file;
import std.datetime;
import std.zip;
import std.zlib;
int main(string[] args)
{
byte[] buffer;
std.zip.ZipArchive zr;
string zipname;
string outzipname;
ubyte[] data;
testzlib();
testzlib2();
if (args.length > 1)
zipname = args[1];
else
zipname = "test.zip";
if (args.length > 2)
outzipname = args[2];
else
outzipname = "foo.zip";
buffer = cast(byte[])std.file.read(zipname);
zr = new std.zip.ZipArchive(cast(void[])buffer);
printf("comment = '%.*s'\n", zr.comment.length, zr.comment.ptr);
writeln(zr.toString());
foreach (ArchiveMember de; zr.directory)
{
writeln(de.toString());
auto s = DosFileTimeToSysTime(de.time).toString();
printf("date = '%.*s'\n", s.length, s.ptr);
arrayPrint(de.compressedData);
data = zr.expand(de);
printf("data = '%.*s'\n", data.length, data.ptr);
}
printf("**Success**\n");
zr = new std.zip.ZipArchive();
ArchiveMember am = new ArchiveMember();
am.compressionMethod = CompressionMethod.deflate;
am.name = "foo.bar";
//am.extra = cast(ubyte[])"ExTrA";
am.expandedData = cast(ubyte[])"We all live in a yellow submarine, a yellow submarine";
zr.addMember(am);
void[] data2 = zr.build();
std.file.write(outzipname, cast(byte[])data2);
return 0;
}
void arrayPrint(ubyte[] array)
{
//printf("array %p,%d\n", (void*)array, array.length);
for (int i = 0; i < array.length; i++)
{
printf("%02x ", array[i]);
if (((i + 1) & 15) == 0)
printf("\n");
}
printf("\n\n");
}
/******************************************/
void testzlib()
{
ubyte[] src = cast(ubyte[])
"the quick brown fox jumps over the lazy dog\r
the quick brown fox jumps over the lazy dog\r
";
ubyte[] dst;
arrayPrint(src);
dst = cast(ubyte[])std.zlib.compress(cast(void[])src);
arrayPrint(dst);
src = cast(ubyte[])std.zlib.uncompress(cast(void[])dst);
arrayPrint(src);
}
/******************************************/
void testzlib2()
{
static ubyte [] buf = [1,2,3,4,5,0,7,8,9];
auto ar = new ZipArchive;
auto am = new ArchiveMember; // 10
am.name = "buf";
am.expandedData = buf;
am.compressionMethod = CompressionMethod.deflate;
am.time = SysTimeToDosFileTime(Clock.currTime());
ar.addMember (am); // 15
auto zip1 = ar.build ();
ar = new ZipArchive (zip1);
}