2021-12-04 20:43:19 +03:00
|
|
|
module main
|
|
|
|
|
|
|
|
import compress.zlib
|
|
|
|
import os
|
|
|
|
|
|
|
|
enum CompressionType {
|
|
|
|
zlib
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
if os.args.len != 5 {
|
|
|
|
eprintln('v compress <type> <in> <out>')
|
|
|
|
eprintln('supported types: zlib')
|
|
|
|
exit(1)
|
|
|
|
}
|
|
|
|
compression_type := match os.args[2] {
|
|
|
|
'zlib' {
|
|
|
|
CompressionType.zlib
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
eprintln('unsupported type: ${os.args[1]}')
|
|
|
|
exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
path := os.args[3]
|
|
|
|
content := os.read_bytes(path) or {
|
2022-11-15 16:53:13 +03:00
|
|
|
eprintln('unable to read "${path}": ${err}')
|
2021-12-04 20:43:19 +03:00
|
|
|
exit(1)
|
|
|
|
}
|
|
|
|
compressed := match compression_type {
|
|
|
|
.zlib {
|
|
|
|
zlib.compress(content) or {
|
2022-11-15 16:53:13 +03:00
|
|
|
eprintln('compression error: ${err}')
|
2021-12-04 20:43:19 +03:00
|
|
|
exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out_path := os.args[4]
|
|
|
|
|
|
|
|
os.write_file_array(out_path, compressed) or {
|
2022-11-15 16:53:13 +03:00
|
|
|
eprintln('failed to write "${out_path}": ${err}')
|
2021-12-04 20:43:19 +03:00
|
|
|
exit(1)
|
|
|
|
}
|
|
|
|
}
|