1 | module main |
2 | |
3 | import compress.zlib |
4 | import os |
5 | |
6 | enum CompressionType { |
7 | zlib |
8 | } |
9 | |
10 | fn 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 | path := os.args[3] |
26 | content := os.read_bytes(path) or { |
27 | eprintln('unable to read "${path}": ${err}') |
28 | exit(1) |
29 | } |
30 | compressed := match compression_type { |
31 | .zlib { |
32 | zlib.compress(content) or { |
33 | eprintln('compression error: ${err}') |
34 | exit(1) |
35 | } |
36 | } |
37 | } |
38 | out_path := os.args[4] |
39 | |
40 | os.write_file_array(out_path, compressed) or { |
41 | eprintln('failed to write "${out_path}": ${err}') |
42 | exit(1) |
43 | } |
44 | } |