From 6e292edbbe8acd6415486744b5b1ef7d35881f95 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Mon, 13 Jun 2022 03:08:29 -0700 Subject: [PATCH] Decode image script --- scripts/decode-image.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 scripts/decode-image.js diff --git a/scripts/decode-image.js b/scripts/decode-image.js new file mode 100644 index 0000000..c708137 --- /dev/null +++ b/scripts/decode-image.js @@ -0,0 +1,25 @@ +/** + * @license + * Copyright (c) 2022 Daniel Imms + * Released under MIT license. See LICENSE in the project root for details. + */ + +const decoder = require('..'); +const fs = require('fs/promises'); +const { extname } = require('path'); + +async function decode(file) { + if (extname(file) !== '.tga') { + throw new Error('File must end with .tga'); + } + const originalData = await fs.readFile(file); + const decoded = await decoder.decodeTga(originalData); + console.log(`Decoded "${file}":`, decoded); +} + +if (process.argv.length < 3) { + console.error('Provide a file as the first argument'); + process.exit(1); +} + +decode(process.argv[2]);