Sample
tar-fs 3.1.4: extract
Verified sample for npm tar-fs 3.1.4: extract. The contract ran on node 22 · linux debian/x64 · docker and passed: tar-fs.extract unpacks nested directories…
sha256:d19ec956a203ae2bdbeee80997f85a3881437300bfee01b33d7b71ee47a08ca0
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 1
- Signing keys that built it
- 1
Declared environment
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-11-29 |
Case
HOW- Goal
- verify tar-fs.extract in pkg:npm/tar-fs@3.1.4
- Packages
- Symbols
-
- tar-fs.extract
- Environment
- node 22.23.2
- Created
- 2026-11-29T22:49:59Z
Contract
- tar-fs.extract unpacks nested directories, file contents, and relative symlinks into the destination directory and invokes the finish callback
- tar-fs.extract skips matching files and symlinks when an ignore(name, header) predicate returns true
- tar-fs.extract strips leading path segments according to the strip option and drops entries stripped to the extraction root
- tar-fs.extract renames entries via map(header) and transforms extracted file contents via mapStream(stream, header)
- tar-fs.extract rejects archive entries containing path traversal segments ('..') with an error and writes nothing outside the target directory
- tar-fs.extract rejects symlinks whose target escapes the extraction directory with an error when symlink validation is enabled
Files
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.js
Source
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify tar-fs.extract in pkg:npm/tar-fs@3.1.4
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/tar-fs@3.1.4
Demonstrate these symbols/APIs:
- tar-fs.extract
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:c29b776d96fe73cd55c7e09503ccef80c139eefff6c8b7fbed973355e03130a9","constraints":{"executionContext":"node"},"contract":["tar-fs.extract unpacks nested directories, file contents, and relative symlinks into the destination directory and invokes the finish callback","tar-fs.extract skips matching files and symlinks when an ignore(name, header) predicate returns true","tar-fs.extract strips leading path segments according to the strip option and drops entries stripped to the extraction root","tar-fs.extract renames entries via map(header) and transforms extracted file contents via mapStream(stream, header)","tar-fs.extract rejects archive entries containing path traversal segments ('..') with an error and writes nothing outside the target directory","tar-fs.extract rejects symlinks whose target escapes the extraction directory with an error when symlink validation is enabled"],"goal":"verify tar-fs.extract in pkg:npm/tar-fs@3.1.4","kind":"HOW","packages":["pkg:npm/tar-fs@3.1.4"],"schemaVersion":1,"symbols":["tar-fs.extract"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/tar-fs@3.1.4"],"schemaVersion":1,"subject":"pkg:npm/tar-fs@3.1.4","symbols":["tar-fs.extract"],"verifierAdapter":"node-typescript@1"}
'use strict'
const tar = require('tar-fs')
/**
* Pipes a readable tar stream into tar-fs.extract targeting destDir.
* Resolves when extraction finishes or rejects on stream error.
*
* @param {import('node:stream').Readable} readable
* @param {string} destDir
* @param {object} [opts]
* @returns {Promise<void>}
*/
function extractTarStream (readable, destDir, opts) {
return new Promise((resolve, reject) => {
const extractor = tar.extract(destDir, opts)
let settled = false
const fail = (err) => {
if (settled) return
settled = true
reject(err)
}
readable.on('error', fail)
extractor.on('error', fail)
extractor.on('finish', () => {
if (settled) return
settled = true
resolve()
})
readable.pipe(extractor)
})
}
module.exports = { extractTarStream }
{
"name": "tar-fs-extract-sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "tar-fs-extract-sample",
"version": "1.0.0",
"dependencies": {
"tar-fs": "3.1.4"
}
},
"node_modules/b4a": {
"version": "1.9.0",
"resolved": "https://registry.npmjs.org/b4a/-/b4a-1.9.0.tgz",
"integrity": "sha512-dpfcF9fDNR6++cthXR67iyhgqWy9CBouAvIWhIntzBG6cvK/cnIPiZQjBwi/ZqjjBEDGfoNDtmB0kTjroOJ3pQ==",
"license": "Apache-2.0",
"peerDependencies": {
"react-native-b4a": "*"
},
"peerDependenciesMeta": {
"react-native-b4a": {
"optional": true
}
}
},
"node_modules/bare-buffer": {
"version": "3.7.3",
"resolved": "https://registry.npmjs.org/bare-buffer/-/bare-buffer-3.7.3.tgz",
"integrity": "sha512-77owW16RX6YgdOzddHtM0oGz8wsd0/F9k/0coz6TPmjUHnr/9FwWODVMNKwyYWM/a/ESdTum855nfQxnsKUygA==",
"license": "Apache-2.0",
"engines": {
"bare": ">=1.20.0"
}
},
"node_modules/bare-events": {
"version": "2.9.2",
"resolved": "https://registry.npmjs.org/bare-events/-/bare-events-2.9.2.tgz",
"integrity": "sha512-AIPKioV7/Y/8KfZ3AAhjPJxLLbY49S64Ym5DakZlUg75qQiTgUq9hEJoEwa4eUezPUlXRy/i5NpsKvo9jgKmoA==",
"license": "Apache-2.0",
"peerDependencies": {
"bare-abort-controller": "*"
},
"peerDependenciesMeta": {
"bare-abort-controller": {
"optional": true
}
}
},
"node_modules/bare-fs": {
"version": "4.8.7",
"resolved": "https://registry.npmjs.org/bare-fs/-/bare-fs-4.8.7.tgz",
"integrity": "sha512-bNBjq+x9Wezp3risJs7TaPH3jjVnyFmmSSxfpES8tp9xjvL4t6Bk9v2nC+xm5lfxJeDzChK7NBryK+JciM/pfQ==",
"license": "Apache-2.0",
"dependencies": {
"bare-events": "^2.5.4",
"bare-path": "^3.0.0",
"bare-stream": "^2.6.4",
"bare-url": "^2.2.2",
"fast-fifo": "^1.3.2"
},
"engines": {
"bare": ">=1.28.0"
},
"peerDependencies": {
"bare-buffer": "*"
},
"peerDependenciesMeta": {
"bare-buffer": {
"optional": true
}
}
},
"node_modules/bare-path": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/bare-path/-/bare-path-3.1.3.tgz",
"integrity": "sha512-8r+FVU/o4zcFmpCDqbqAYhHHbtXPP+cyZKo7DRGRWc7OLlNs4TMaSQEpXL/sIdzyEG0M7RHw4B7xYMGrTc+qrg==",
"license": "Apache-2.0"
},
"node_modules/bare-stream": {
"version": "2.13.4",
"resolved": "https://registry.npmjs.org/bare-stream/-/bare-stream-2.13.4.tgz",
"integrity": "sha512-PcrQ8lVLbiJscNm1Kez+Yp4Gy4AHGcN1lzwjvf5NybWen7VvEgUfyfnXYJ2zNqWnzOfCb1Abq6lH8ti0syQszA==",
"license": "Apache-2.0",
"dependencies": {
"b4a": "^1.8.1",
"streamx": "^2.25.0",
"teex": "^1.0.1"
},
"peerDependencies": {
"bare-abort-controller": "*",
"bare-buffer": "*",
"bare-events": "*"
},
"peerDependenciesMeta": {
"bare-abort-controller": {
"optional": true
},
"bare-buffer": {
"optional": true
},
"bare-events": {
"optional": true
}
}
},
"node_modules/bare-url": {
"version": "2.5.8",
"resolved": "https://registry.npmjs.org/bare-url/-/bare-url-2.5.8.tgz",
"integrity": "sha512-G5KTe5Bj6z5pqIxcn3lWlIFIv0rkXbccx0T0Xuf7t4RapfSWvFlcVbrwYXxFZ00PC4lp57OCIk6uXP/r3GbpDw==",
"license": "Apache-2.0",
"dependencies": {
"bare-buffer": "^3.0.0",
"bare-path": "^3.0.0"
}
},
"node_modules/end-of-stream": {
"version": "1.4.5",
"resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.5.tgz",
"integrity": "sha512-ooEGc6HP26xXq/N+GCGOT0JKCLDGrq2bQUZrQ7gyrJiZANJ/8YDTxTpQBXGMn+WbIQXNVpyWymm7KYVICQnyOg==",
"license": "MIT",
"dependencies": {
"once": "^1.4.0"
}
},
"node_modules/events-universal": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/events-universal/-/events-universal-1.0.1.tgz",
"integrity": "sha512-LUd5euvbMLpwOF8m6ivPCbhQeSiYVNb8Vs0fQ8QjXo0JTkEHpz8pxdQf0gStltaPpw0Cca8b39KxvK9cfKRiAw==",
"license": "Apache-2.0",
"dependencies": {
"bare-events": "^2.7.0"
}
},
"node_modules/fast-fifo": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/fast-fifo/-/fast-fifo-1.3.2.tgz",
"integrity": "sha512-/d9sfos4yxzpwkDkuN7k2SqFKtYNmCTzgfEpz82x34IM9/zc8KGxQoXg1liNC/izpRM/MBdt44Nmx41ZWqk+FQ==",
"license": "MIT"
},
"node_modules/once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",
"license": "ISC",
"dependencies": {
"wrappy": "1"
}
},
"node_modules/pump": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.4.tgz",
"integrity": "sha512-VS7sjc6KR7e1ukRFhQSY5LM2uBWAUPiOPa/A3mkKmiMwSmRFUITt0xuj+/lesgnCv+dPIEYlkzrcyXgquIHMcA==",
"license": "MIT",
"dependencies": {
"end-of-stream": "^1.1.0",
"once": "^1.3.1"
}
},
"node_modules/streamx": {
"version": "2.28.1",
"resolved": "https://registry.npmjs.org/streamx/-/streamx-2.28.1.tgz",
"integrity": "sha512-zEzXb0s5Cds7tqMH6rhZ05lcJydCWiQPEwiNngVqzsxCc962vLY4Uw+mW7od8kDH258k2Uz/JrOkdIAAhSh9VA==",
"license": "MIT",
"dependencies": {
"events-universal": "^1.0.0",
"fast-fifo": "^1.3.2",
"text-decoder": "^1.1.0"
}
},
"node_modules/tar-fs": {
"version": "3.1.4",
"resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-3.1.4.tgz",
"integrity": "sha512-S0lrlrJkynj6otwBGsd+1YHWvbgac42+LeHavSzgokehNdiRg1D4eGFDi1cceiG1fQlSTnnss+agdRQl5Bb1DA==",
"license": "MIT",
"dependencies": {
"pump": "^3.0.0",
"tar-stream": "^3.3.0"
},
"optionalDependencies": {
"bare-fs": "^4.0.1",
"bare-path": "^3.0.0"
}
},
"node_modules/tar-stream": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-3.3.0.tgz",
"integrity": "sha512-rQZZfW2Q4YDCFJyP8KFDG+gfMzcOHaMYq0gb9jzH2gsK0P5qXVpu+UoKE1qaZcs3/R6QVkJr2228nlZoM1V5PA==",
"license": "MIT",
"dependencies": {
"b4a": "^1.9.0",
"bare-fs": "^4.8.2",
"fast-fifo": "^1.3.2",
"streamx": "^2.28.1"
}
},
"node_modules/teex": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/teex/-/teex-1.0.1.tgz",
"integrity": "sha512-eYE6iEI62Ni1H8oIa7KlDU6uQBtqr4Eajni3wX7rpfXD8ysFx8z0+dri+KWEPWpBsxXfxu58x/0jvTVT1ekOSg==",
"license": "MIT",
"dependencies": {
"streamx": "^2.12.5"
}
},
"node_modules/text-decoder": {
"version": "1.2.7",
"resolved": "https://registry.npmjs.org/text-decoder/-/text-decoder-1.2.7.tgz",
"integrity": "sha512-vlLytXkeP4xvEq2otHeJfSQIRyWxo/oZGEbXrtEEF9Hnmrdly59sUbzZ/QgyWuLYHctCHxFF4tRQZNQ9k60ExQ==",
"license": "Apache-2.0",
"dependencies": {
"b4a": "^1.6.4"
}
},
"node_modules/wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
"license": "ISC"
}
}
}
{
"name": "tar-fs-extract-sample",
"version": "1.0.0",
"private": true,
"description": "Minimal sample verifying tar-fs.extract behavior",
"main": "index.js",
"scripts": {
"test": "node test/contract.js"
},
"dependencies": {
"tar-fs": "3.1.4"
}
}
{
"schemaVersion": 1,
"goal": "verify tar-fs.extract in pkg:npm/tar-fs@3.1.4",
"kind": "HOW",
"packages": [
"pkg:npm/tar-fs@3.1.4"
],
"symbols": [
"tar-fs.extract"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
'use strict'
const assert = require('node:assert/strict')
const fs = require('node:fs')
const os = require('node:os')
const path = require('node:path')
const { Readable, Transform } = require('node:stream')
const tar = require('tar-fs')
const { extractTarStream } = require('../index')
function writeOctal (buf, offset, length, value) {
const str = value.toString(8).padStart(length - 1, '0')
buf.write(str, offset, length - 1, 'ascii')
buf[offset + length - 1] = 0
}
function buildTarBuffer (entries) {
const chunks = []
const nowSec = Math.floor(Date.now() / 1000)
for (const entry of entries) {
const header = Buffer.alloc(512, 0)
const content = entry.content ? Buffer.from(entry.content) : Buffer.alloc(0)
const typeflag = entry.type === 'symlink' ? '2' : entry.type === 'directory' ? '5' : '0'
const mode = entry.mode ?? (typeflag === '5' ? 0o755 : 0o644)
header.write(entry.name, 0, 100, 'utf8')
writeOctal(header, 100, 8, mode)
writeOctal(header, 108, 8, 0)
writeOctal(header, 116, 8, 0)
writeOctal(header, 124, 12, content.length)
writeOctal(header, 136, 12, nowSec)
header.fill(0x20, 148, 156)
header.write(typeflag, 156, 1, 'ascii')
if (entry.linkname) {
header.write(entry.linkname, 157, 100, 'utf8')
}
header.write('ustar\0', 257, 6, 'ascii')
header.write('00', 263, 2, 'ascii')
let checksum = 0
for (let i = 0; i < 512; i++) checksum += header[i]
const chk = checksum.toString(8).padStart(6, '0')
header.write(chk, 148, 6, 'ascii')
header[154] = 0
header[155] = 0x20
chunks.push(header)
if (content.length > 0) {
chunks.push(content)
const remainder = content.length % 512
if (remainder !== 0) {
chunks.push(Buffer.alloc(512 - remainder, 0))
}
}
}
chunks.push(Buffer.alloc(1024, 0))
return Buffer.concat(chunks)
}
async function main () {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'tar-fs-extract-'))
try {
// Prepare a fixture directory to pack with tar-fs.pack
const srcDir = path.join(root, 'src')
fs.mkdirSync(path.join(srcDir, 'nested', 'deep'), { recursive: true })
fs.writeFileSync(path.join(srcDir, 'hello.txt'), 'hello world\n')
fs.writeFileSync(path.join(srcDir, 'skip.log'), 'ignored content')
fs.writeFileSync(path.join(srcDir, 'nested', 'deep', 'data.txt'), 'nested data')
fs.symlinkSync('hello.txt', path.join(srcDir, 'link-hello.txt'))
// 1. Basic extraction of directories, files, and relative symlinks + finish callback
const outBasic = path.join(root, 'out-basic')
let finishCalled = false
await extractTarStream(tar.pack(srcDir), outBasic, {
finish () {
finishCalled = true
}
})
assert.equal(finishCalled, true, 'finish option callback should be invoked')
assert.equal(fs.readFileSync(path.join(outBasic, 'hello.txt'), 'utf8'), 'hello world\n')
assert.equal(fs.readFileSync(path.join(outBasic, 'nested', 'deep', 'data.txt'), 'utf8'), 'nested data')
assert.equal(fs.lstatSync(path.join(outBasic, 'link-hello.txt')).isSymbolicLink(), true)
assert.equal(fs.readlinkSync(path.join(outBasic, 'link-hello.txt')), 'hello.txt')
// 2. ignore option filters out matching entries
const outIgnore = path.join(root, 'out-ignore')
await extractTarStream(tar.pack(srcDir), outIgnore, {
ignore (name, header) {
return name.endsWith('.log') || header.type === 'symlink'
}
})
assert.equal(fs.existsSync(path.join(outIgnore, 'hello.txt')), true)
assert.equal(fs.existsSync(path.join(outIgnore, 'skip.log')), false)
assert.equal(fs.existsSync(path.join(outIgnore, 'link-hello.txt')), false)
// 3. strip option removes leading directory segments and drops stripped root files
const outStrip = path.join(root, 'out-strip')
await extractTarStream(tar.pack(srcDir), outStrip, { strip: 1 })
assert.equal(fs.existsSync(path.join(outStrip, 'hello.txt')), false)
assert.equal(fs.readFileSync(path.join(outStrip, 'deep', 'data.txt'), 'utf8'), 'nested data')
// 4. map and mapStream transform entry names and file contents on the fly
const outMap = path.join(root, 'out-map')
await extractTarStream(tar.pack(srcDir), outMap, {
ignore (name) {
return name.endsWith('.log')
},
map (header) {
if (header.name === 'hello.txt') {
header.name = 'renamed.txt'
}
return header
},
mapStream (fileStream, header) {
if (header.name !== 'renamed.txt') return fileStream
return fileStream.pipe(new Transform({
transform (chunk, _enc, cb) {
cb(null, Buffer.from(chunk.toString('utf8').toUpperCase()))
}
}))
}
})
assert.equal(fs.existsSync(path.join(outMap, 'hello.txt')), false)
assert.equal(fs.readFileSync(path.join(outMap, 'renamed.txt'), 'utf8'), 'HELLO WORLD\n')
// 5. Security validation: rejects path traversal entries containing '..'
const outTraversal = path.join(root, 'out-traversal')
const traversalTar = buildTarBuffer([
{ name: '../escape.txt', type: 'file', content: 'blocked' }
])
await assert.rejects(
extractTarStream(Readable.from([traversalTar]), outTraversal),
/is not a valid path/
)
assert.equal(fs.existsSync(path.join(root, 'escape.txt')), false)
// 6. Security validation: rejects symlinks escaping extraction directory
const outSymlink = path.join(root, 'out-symlink')
const escapeSymlinkTar = buildTarBuffer([
{ name: 'bad-link', type: 'symlink', linkname: '../../outside.txt' }
])
await assert.rejects(
extractTarStream(Readable.from([escapeSymlinkTar]), outSymlink),
/is not a valid symlink/
)
assert.equal(fs.existsSync(path.join(outSymlink, 'bad-link')), false)
console.log('ALL CONTRACT ASSERTIONS PASSED')
} finally {
fs.rmSync(root, { recursive: true, force: true })
}
}
main().catch((err) => {
console.error(err)
process.exit(1)
})
Origin Seeder
anonymous