From d6be4a685e15e87a1f3826483e9bd17b896c7ffd Mon Sep 17 00:00:00 2001 From: theMackabu Date: Tue, 10 Mar 2026 19:32:29 -0700 Subject: [PATCH] add (non-functional for now) tar example --- examples/npm/smoke/package.json | 6 +--- examples/npm/tar/ant.lockb | Bin 0 -> 1480 bytes examples/npm/tar/index.js | 53 ++++++++++++++++++++++++++++++++ examples/npm/tar/package.json | 12 ++++++++ 4 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 examples/npm/tar/ant.lockb create mode 100644 examples/npm/tar/index.js create mode 100644 examples/npm/tar/package.json diff --git a/examples/npm/smoke/package.json b/examples/npm/smoke/package.json index 96887d2..b7e7a44 100644 --- a/examples/npm/smoke/package.json +++ b/examples/npm/smoke/package.json @@ -1,10 +1,6 @@ { "name": "smoke", "type": "module", - "main": "index.js", - "scripts": { - "start": "ant index.js" - }, "dependencies": { "uuid": "^13.0.0", "ms": "^2.1.3", @@ -27,4 +23,4 @@ "handlebars": "^4.7.8" }, "devDependencies": {} -} \ No newline at end of file +} diff --git a/examples/npm/tar/ant.lockb b/examples/npm/tar/ant.lockb new file mode 100644 index 0000000000000000000000000000000000000000..6e5f65a68c3cf3dc666235d17b5b30b17caca765 GIT binary patch literal 1480 zcmeZq_YPoWU|?WlU|?WpU|?`yU|?9r$iVP|k%2*im4Tsym4ShS0XHZ~EXpV;DJZtm z*Dp#<&nzw}s?^IX$jvI&%P&gTFG(!Y*9DQf=6a@jhK712=~Z#&dWL#NaVB~OdIoXE zdWL!iai&nVfu2EbW?p7NVsSAZLt#qvb@gFPU67f^Ak!T(ixU%*i}llrbzzctjKZQ? zUl&=gF36cMXB+65fXuAQ$xOmyCQJ#`c_7ugU~ht)SDBcTlUZDXM>|x7zOFu$r3(%n zkmlr!{PH|}!3|NMud5GX=o*8<6{Hgqf6UN02Ju)y1Oo#DH`sfxd+N+IK;VENV2SN`YQXH5C3`HZXYYinNro~Y=&VtMn2S!^1Yr+-Ha4^V!G*`@8A z6s6Ay$^XdV1hyEBNaDWY`$y~Kxht{3+U!p{W*v?2O1bp0{;k*USkuWIGtMu6|3rA5 zO8Ci&WtS4NeT(B(o4Q_D+SX8fuUj=qBbN~_pW#=45NLd6650E%E z{G+Eh`9h>6dwtw9ez&amf)PjmRV{wzA^gZu>ur?$8Y`YFXENLj#U^cNy5sHLJwG^f zjiC?czeSr0MA@}hIG6q^Vq{=2K{6QG9i_QSR-mvkf|iRQWlYfU1BDxi4|1O!k~}CK zxghaD;pm0L2buR0jgM?T$jtx$|NqY{T(AzL_7V%*Hjtf*rIxJ&+2ymg1D;hu>cXa_ OeFNF?TudtfWH$hZnR}rC literal 0 HcmV?d00001 diff --git a/examples/npm/tar/index.js b/examples/npm/tar/index.js new file mode 100644 index 0000000..a5eff40 --- /dev/null +++ b/examples/npm/tar/index.js @@ -0,0 +1,53 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import os from 'node:os'; +import * as tar from 'tar'; + +const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'tar-test-')); +const src = path.join(tmp, 'src'); +const dest = path.join(tmp, 'dest'); +const archive = path.join(tmp, 'test.tar.gz'); + +fs.mkdirSync(src, { recursive: true }); +fs.writeFileSync(path.join(src, 'hello.txt'), 'Hello, World!\n'); +fs.writeFileSync(path.join(src, 'data.json'), '{"a":1}'); +fs.mkdirSync(path.join(dest), { recursive: true }); + +async function run() { + console.log('1. Creating tarball...'); + await tar.create({ file: archive, cwd: tmp, gzip: true }, ['src']); + if (!fs.existsSync(archive) || fs.statSync(archive).size === 0) { + console.log('FAIL — archive not created'); + process.exit(1); + } + console.log(' OK — archive created (%d bytes)', fs.statSync(archive).size); + + console.log('2. Extracting tarball...'); + await tar.extract({ file: archive, cwd: dest }); + if (!fs.existsSync(path.join(dest, 'src', 'hello.txt'))) { + console.log('FAIL — files not extracted'); + process.exit(1); + } + console.log(' OK — files extracted'); + + console.log('3. Verifying contents...'); + const original1 = fs.readFileSync(path.join(src, 'hello.txt'), 'utf8'); + const extracted1 = fs.readFileSync(path.join(dest, 'src', 'hello.txt'), 'utf8'); + const original2 = fs.readFileSync(path.join(src, 'data.json'), 'utf8'); + const extracted2 = fs.readFileSync(path.join(dest, 'src', 'data.json'), 'utf8'); + + if (original1 !== extracted1 || original2 !== extracted2) { + console.log('FAIL — content mismatch'); + process.exit(1); + } + console.log(' OK — contents match'); + + console.log('\nAll good.'); + fs.rmSync(tmp, { recursive: true, force: true }); +} + +run().catch(err => { + console.error('FAIL —', err.message); + fs.rmSync(tmp, { recursive: true, force: true }); + process.exit(1); +}); diff --git a/examples/npm/tar/package.json b/examples/npm/tar/package.json new file mode 100644 index 0000000..94833f2 --- /dev/null +++ b/examples/npm/tar/package.json @@ -0,0 +1,12 @@ +{ + "name": "tar", + "type": "module", + "main": "index.js", + "scripts": { + "start": "ant index.js" + }, + "dependencies": { + "tar": "^7.5.11" + }, + "devDependencies": {} +} \ No newline at end of file -- 2.51.2