v / cmd / tools / vcompress.v
46 lines · 40 sloc · 763 bytes · 8e35f4d9848f7ad35d857a187dddbfd2eca5e19d
Raw
1module main
2
3import compress.zlib
4import os
5
6enum CompressionType {
7 zlib
8}
9
10fn main() {
11 if os.args.len != 5 {
12 eprintln('v compress <type> <in> <out>')
13 eprintln('supported types: zlib')
14 exit(1)
15 }
16 compression_type := match os.args[2] {
17 'zlib' {
18 CompressionType.zlib
19 }
20 else {
21 eprintln('unsupported type: ${os.args[1]}')
22 exit(1)
23 }
24 }
25
26 path := os.args[3]
27 content := os.read_bytes(path) or {
28 eprintln('unable to read "${path}": ${err}')
29 exit(1)
30 }
31 compressed := match compression_type {
32 .zlib {
33 zlib.compress(content) or {
34 eprintln('compression error: ${err}')
35 exit(1)
36 }
37 }
38 }
39
40 out_path := os.args[4]
41
42 os.write_file_array(out_path, compressed) or {
43 eprintln('failed to write "${out_path}": ${err}')
44 exit(1)
45 }
46}
47