From beecc0b5eb34a1a9ab22e3ac96263d4ab1e49335 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Wed, 10 May 2023 09:19:18 +0900 Subject: [PATCH] gzip impl --- assets/disk0/tvdos/bin/gzip.js | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/assets/disk0/tvdos/bin/gzip.js b/assets/disk0/tvdos/bin/gzip.js index 0ec220a..0f6c90b 100644 --- a/assets/disk0/tvdos/bin/gzip.js +++ b/assets/disk0/tvdos/bin/gzip.js @@ -13,4 +13,35 @@ To decompress a gzipped file specifying the output filename: if (exec_args[1] === undefined) { printUsage() return 0 -} \ No newline at end of file +} + +const options = exec_args.filter(it=>it.startsWith("/")).map(it=>it.toUpperCase()) +const filePath = exec_args.filter(it=>!it.startsWith("/"))[1] + +if (filePath === undefined) { + printUsage() + return 0 +} + +const decompMode = (options.indexOf("/D") >= 0) +const toStdout = (options.indexOf("/C") >= 0) + + +const file = files.open(_G.shell.resolvePath(filePath).full) + +// returns Java byte[] +const actionfun = if (decompMode) + (str) => gzip.decomp(str) +else + (str) => gzip.comp(str) + + +const writefun = if (toStdout) + (bytes) => print(String.fromCharCode.apply(null, bytes)) +else + (bytes) => file.swrite(String.fromCharCode.apply(null, bytes)) + + +//////////////////////////////////////// + +writefun(actionfun(file.sread()))