1 module chunker.example;
2 
3 import std.stdio : File, writefln;
4 import std.digest.sha : sha256Of;
5 
6 import chunker;
7 import chunker.polynomials;
8 import chunker.internal.helpers : getRandom;
9 
10 void main()
11 {
12 	// generate 32MiB of deterministic pseudo-random data
13 	auto data = getRandom(23, 32*1024*1024);
14 	File("temp.bin", "wb").rawWrite(data);
15 
16 	// reuse this buffer
17 	auto buf = new ubyte[8*1024*1024];
18 
19 	// create a chunker
20 	auto chunker = File("temp.bin", "rb")
21 		.byChunk(512 * 1024)
22 		.byCDChunk(Pol(0x3DA3358B4DC173), buf);
23 
24 	foreach (i; 0 .. 5)
25 	{
26 		if (chunker.empty)
27 			break;
28 		auto chunk = chunker.front;
29 
30 		writefln!"%d %(%02x%)"(chunk.data.length, sha256Of(chunk.data));
31 		chunker.popFront();
32 	}
33 
34 	// Output:
35 	// 2163460 4b94cb2cf293855ea43bf766731c74969b91aa6bf3c078719aabdd19860d590d
36 	// 643703 5727a63c0964f365ab8ed2ccf604912f2ea7be29759a2b53ede4d6841e397407
37 	// 1528956 a73759636a1e7a2758767791c69e81b69fb49236c6929e5d1b654e06e37674ba
38 	// 1955808 c955fb059409b25f07e5ae09defbbc2aadf117c97a3724e06ad4abd2787e6824
39 	// 2222372 6ba5e9f7e1b310722be3627716cf469be941f7f3e39a4c3bcefea492ec31ee56
40 }