1 module balzeos
/*is aliced*/;
7 // ////////////////////////////////////////////////////////////////////////// //
10 string t
= to
!string(n
);
11 if (t
.length
< 4) return t
;
13 while (t
.length
> 3) {
14 res
= ","~t
[$-3..$]~res
;
17 if (t
.length
) res
= t
~res
; else res
= res
[1..$];
22 // ////////////////////////////////////////////////////////////////////////// //
23 version = show_progress
;
25 int main (string
[] args
) {
27 import core
.stdc
.time
;
30 if (args
.length
!= 4) {
32 "BALZ - A ROLZ-based file compressor, v1.20\n"~
34 "Usage: BALZ command infile outfile\n"~
37 " c|cx Compress (Normal|Maximum)\n"~
43 auto fin
= File(args
[2]);
44 auto fout
= File(args
[3], "w");
46 if (args
[1][0] == 'c') {
48 writefln("Compressing: %s -> %s", args
[2], args
[3]);
50 fout
.rawWrite((&fsz
)[0..1]);
51 version(show_progress
) {
52 auto stt
= MonoTime
.currTime
;
54 long totalWritten
= 0;
55 long prevRead
= 0, prevWritten
= 0;
58 if (prevRead
== 0 || prevWritten
== 0 || totalRead
-prevRead
>= 1024*1024 || totalWritten
-prevWritten
>= 1024*1024) {
59 auto ctt
= MonoTime
.currTime
;
60 if ((ctt
-stt
).total
!"seconds" > 0) {
63 prevWritten
= totalWritten
;
64 stdout
.write("\r[", totalRead
.n2c
, "/", fsz
.n2c
, "] [", totalWritten
.n2c
, "]");
74 auto res
= fin
.rawRead(buf
[]);
75 version(show_progress
) {
76 totalRead
+= res
.length
;
79 return cast(uint)res
.length
;
84 version(show_progress
) {
85 totalWritten
+= buf
.length
;
90 args
[1].length
> 1 && args
[1][1] == 'x'
92 writefln("\r%s -> %s in %.3fs\x1b[K", fin
.size
.n2c
, fout
.size
.n2c
, double(clock()-start
)/CLOCKS_PER_SEC
);
93 } else if (args
[1][0] == 'd' || args
[1][0] == 'x') {
95 writefln("Decompressing: %s -> %s", args
[2], args
[3]);
97 fin
.rawRead((&fsz
)[0..1]);
99 //auto stt = MonoTime.currTime;
100 auto dc
= bz
.decompress(
102 (buf
) { auto res
= fin
.rawRead(buf
[]); return cast(uint)res
.length
; },
104 (buf
) { fout
.rawWrite(buf
[]); },
106 if (dc
!= fsz
) writeln("INVALID STREAM SIZE: got ", dc
, " but expected ", fsz
);
107 writefln("%s -> %s in %.3fs", fin
.size
.n2c
, fout
.size
.n2c
, double(clock()-start
)/CLOCKS_PER_SEC
);
109 writefln("Unknown command: %s", args
[1]);