MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

add (non-functional for now) tar example

+66 -5
+1 -5
examples/npm/smoke/package.json
··· 1 1 { 2 2 "name": "smoke", 3 3 "type": "module", 4 - "main": "index.js", 5 - "scripts": { 6 - "start": "ant index.js" 7 - }, 8 4 "dependencies": { 9 5 "uuid": "^13.0.0", 10 6 "ms": "^2.1.3", ··· 27 23 "handlebars": "^4.7.8" 28 24 }, 29 25 "devDependencies": {} 30 - } 26 + }
examples/npm/tar/ant.lockb

This is a binary file and will not be displayed.

+53
examples/npm/tar/index.js
··· 1 + import fs from 'node:fs'; 2 + import path from 'node:path'; 3 + import os from 'node:os'; 4 + import * as tar from 'tar'; 5 + 6 + const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'tar-test-')); 7 + const src = path.join(tmp, 'src'); 8 + const dest = path.join(tmp, 'dest'); 9 + const archive = path.join(tmp, 'test.tar.gz'); 10 + 11 + fs.mkdirSync(src, { recursive: true }); 12 + fs.writeFileSync(path.join(src, 'hello.txt'), 'Hello, World!\n'); 13 + fs.writeFileSync(path.join(src, 'data.json'), '{"a":1}'); 14 + fs.mkdirSync(path.join(dest), { recursive: true }); 15 + 16 + async function run() { 17 + console.log('1. Creating tarball...'); 18 + await tar.create({ file: archive, cwd: tmp, gzip: true }, ['src']); 19 + if (!fs.existsSync(archive) || fs.statSync(archive).size === 0) { 20 + console.log('FAIL โ€” archive not created'); 21 + process.exit(1); 22 + } 23 + console.log(' OK โ€” archive created (%d bytes)', fs.statSync(archive).size); 24 + 25 + console.log('2. Extracting tarball...'); 26 + await tar.extract({ file: archive, cwd: dest }); 27 + if (!fs.existsSync(path.join(dest, 'src', 'hello.txt'))) { 28 + console.log('FAIL โ€” files not extracted'); 29 + process.exit(1); 30 + } 31 + console.log(' OK โ€” files extracted'); 32 + 33 + console.log('3. Verifying contents...'); 34 + const original1 = fs.readFileSync(path.join(src, 'hello.txt'), 'utf8'); 35 + const extracted1 = fs.readFileSync(path.join(dest, 'src', 'hello.txt'), 'utf8'); 36 + const original2 = fs.readFileSync(path.join(src, 'data.json'), 'utf8'); 37 + const extracted2 = fs.readFileSync(path.join(dest, 'src', 'data.json'), 'utf8'); 38 + 39 + if (original1 !== extracted1 || original2 !== extracted2) { 40 + console.log('FAIL โ€” content mismatch'); 41 + process.exit(1); 42 + } 43 + console.log(' OK โ€” contents match'); 44 + 45 + console.log('\nAll good.'); 46 + fs.rmSync(tmp, { recursive: true, force: true }); 47 + } 48 + 49 + run().catch(err => { 50 + console.error('FAIL โ€”', err.message); 51 + fs.rmSync(tmp, { recursive: true, force: true }); 52 + process.exit(1); 53 + });
+12
examples/npm/tar/package.json
··· 1 + { 2 + "name": "tar", 3 + "type": "module", 4 + "main": "index.js", 5 + "scripts": { 6 + "start": "ant index.js" 7 + }, 8 + "dependencies": { 9 + "tar": "^7.5.11" 10 + }, 11 + "devDependencies": {} 12 + }