-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstreaming.d
34 lines (27 loc) · 951 Bytes
/
streaming.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
import zstd;
static import std.file;
static import std.stdio;
void main(string[] args)
{
if (args.length <= 1)
throw new Exception("Must specify filename");
ubyte[] original = cast(ubyte[])std.file.read(args[1]);
ubyte[][] contents1;
contents1 ~= original[0..$ / 2];
contents1 ~= original[$ / 2..$];
ubyte[] compressed;
auto compressor = new Compressor();
foreach (src; contents1)
compressed ~= compressor.compress(src);
compressed ~= compressor.flush();
std.stdio.writefln("original size: %d", original.length);
std.stdio.writefln("compressed size: %d", compressed.length);
ubyte[][] contents2;
contents2 ~= compressed[0..$ / 2];
contents2 ~= compressed[$ / 2..$];
ubyte[] decompressed;
auto uncompressor = new Decompressor();
foreach (src; contents2)
decompressed ~= uncompressor.decompress(src);
std.stdio.writeln(original == decompressed);
}