CodeSampleX

Ejemplo

tar-stream 2.2.0: pack

Muestra verificada para npm tar-stream 2.2.0: pack. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó: tar.pack returns a readable stream…

sha256:044266eaa04e21dc002116adacd5e2bfa6cdc9fa2ddef0fdf83fbb2df79d9ca5

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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-09-04

Caso

HOW
Objetivo
verify tar-stream.pack in pkg:npm/tar-stream@2.2.0
Paquetes
Símbolos
  • tar-stream.pack
Entorno
node 22.23.2
Creado
2026-09-04T13:27:37Z

Contrato

  1. tar.pack returns a readable stream that yields 512-byte aligned blocks and terminates with a 1024-byte zero block after finalize
  2. pack.entry buffers string or Buffer payload with custom header metadata and writes padded tar blocks
  3. pack.entry returns a writable sink stream when payload is omitted and finalizes after streaming exactly header.size bytes
  4. pack.entry destroys the pack stream and reports size mismatch when streamed bytes do not match header.size
  5. pack.entry throws an error when called while another entry stream is still actively piping
  6. pack.entry writes directory entries with type directory, default 0755 mode, zero size, and returns a void sink

Archivos

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

Descargar el artefacto de código fuente (tar.gz)

Código fuente

PROMPT.md
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-stream.pack in pkg:npm/tar-stream@2.2.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/tar-stream@2.2.0
Demonstrate these symbols/APIs:
  - tar-stream.pack

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.
csx.json
{"case":{"caseId":"case:sha256:9378eb95a92e632c91e33459e23bdc5269a93f92ec96e223c6206ee95869ad0d","constraints":{"executionContext":"node"},"contract":["tar.pack returns a readable stream that yields 512-byte aligned blocks and terminates with a 1024-byte zero block after finalize","pack.entry buffers string or Buffer payload with custom header metadata and writes padded tar blocks","pack.entry returns a writable sink stream when payload is omitted and finalizes after streaming exactly header.size bytes","pack.entry destroys the pack stream and reports size mismatch when streamed bytes do not match header.size","pack.entry throws an error when called while another entry stream is still actively piping","pack.entry writes directory entries with type directory, default 0755 mode, zero size, and returns a void sink"],"goal":"verify tar-stream.pack in pkg:npm/tar-stream@2.2.0","kind":"HOW","packages":["pkg:npm/tar-stream@2.2.0"],"schemaVersion":1,"symbols":["tar-stream.pack"]},"contractCommand":["node","test/contract.mjs"],"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-stream@2.2.0"],"schemaVersion":1,"subject":"pkg:npm/tar-stream@2.2.0","symbols":["tar-stream.pack"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-tar-stream-pack",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-tar-stream-pack",
      "version": "1.0.0",
      "dependencies": {
        "tar-stream": "2.2.0"
      }
    },
    "node_modules/base64-js": {
      "version": "1.5.1",
      "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
      "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==",
      "funding": [
        {
          "type": "github",
          "url": "https://github.com/sponsors/feross"
        },
        {
          "type": "patreon",
          "url": "https://www.patreon.com/feross"
        },
        {
          "type": "consulting",
          "url": "https://feross.org/support"
        }
      ],
      "license": "MIT"
    },
    "node_modules/bl": {
      "version": "4.1.0",
      "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz",
      "integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==",
      "license": "MIT",
      "dependencies": {
        "buffer": "^5.5.0",
        "inherits": "^2.0.4",
        "readable-stream": "^3.4.0"
      }
    },
    "node_modules/buffer": {
      "version": "5.7.1",
      "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
      "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",
      "funding": [
        {
          "type": "github",
          "url": "https://github.com/sponsors/feross"
        },
        {
          "type": "patreon",
          "url": "https://www.patreon.com/feross"
        },
        {
          "type": "consulting",
          "url": "https://feross.org/support"
        }
      ],
      "license": "MIT",
      "dependencies": {
        "base64-js": "^1.3.1",
        "ieee754": "^1.1.13"
      }
    },
    "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/fs-constants": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz",
      "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==",
      "license": "MIT"
    },
    "node_modules/ieee754": {
      "version": "1.2.1",
      "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
      "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==",
      "funding": [
        {
          "type": "github",
          "url": "https://github.com/sponsors/feross"
        },
        {
          "type": "patreon",
          "url": "https://www.patreon.com/feross"
        },
        {
          "type": "consulting",
          "url": "https://feross.org/support"
        }
      ],
      "license": "BSD-3-Clause"
    },
    "node_modules/inherits": {
      "version": "2.0.4",
      "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
      "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
      "license": "ISC"
    },
    "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/readable-stream": {
      "version": "3.6.2",
      "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz",
      "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==",
      "license": "MIT",
      "dependencies": {
        "inherits": "^2.0.3",
        "string_decoder": "^1.1.1",
        "util-deprecate": "^1.0.1"
      },
      "engines": {
        "node": ">= 6"
      }
    },
    "node_modules/safe-buffer": {
      "version": "5.2.1",
      "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
      "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
      "funding": [
        {
          "type": "github",
          "url": "https://github.com/sponsors/feross"
        },
        {
          "type": "patreon",
          "url": "https://www.patreon.com/feross"
        },
        {
          "type": "consulting",
          "url": "https://feross.org/support"
        }
      ],
      "license": "MIT"
    },
    "node_modules/string_decoder": {
      "version": "1.3.0",
      "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
      "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==",
      "license": "MIT",
      "dependencies": {
        "safe-buffer": "~5.2.0"
      }
    },
    "node_modules/tar-stream": {
      "version": "2.2.0",
      "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz",
      "integrity": "sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==",
      "license": "MIT",
      "dependencies": {
        "bl": "^4.0.3",
        "end-of-stream": "^1.4.1",
        "fs-constants": "^1.0.0",
        "inherits": "^2.0.3",
        "readable-stream": "^3.1.1"
      },
      "engines": {
        "node": ">=6"
      }
    },
    "node_modules/util-deprecate": {
      "version": "1.0.2",
      "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
      "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==",
      "license": "MIT"
    },
    "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"
    }
  }
}
package.json
{
  "name": "sample-tar-stream-pack",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "tar-stream": "2.2.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify tar-stream.pack in pkg:npm/tar-stream@2.2.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/tar-stream@2.2.0"
  ],
  "symbols": [
    "tar-stream.pack"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { Buffer } from 'node:buffer';
import tar from 'tar-stream';

// 1. tar.pack returns a readable stream that yields 512-byte aligned blocks and terminates with a 1024-byte zero block after finalize
await new Promise((resolve, reject) => {
	const pack = tar.pack();
	const chunks = [];

	pack.on('data', (chunk) => chunks.push(chunk));
	pack.on('end', () => {
		try {
			const tarBuf = Buffer.concat(chunks);
			assert.ok(tarBuf.length >= 1024);
			assert.equal(tarBuf.length % 512, 0);
			const trailer = tarBuf.subarray(tarBuf.length - 1024);
			assert.deepEqual(trailer, Buffer.alloc(1024, 0));
			resolve();
		} catch (err) {
			reject(err);
		}
	});
	pack.on('error', reject);

	pack.finalize();
});

// 2. pack.entry buffers string or Buffer payload with custom header metadata and writes padded tar blocks
await new Promise((resolve, reject) => {
	const pack = tar.pack();
	const chunks = [];

	pack.on('data', (chunk) => chunks.push(chunk));
	pack.on('end', () => {
		try {
			const tarBuf = Buffer.concat(chunks);
			assert.equal(tarBuf.length % 512, 0);

			// Inspect header at offset 0
			const name = tarBuf
				.subarray(0, 100)
				.toString('utf8')
				.replace(/\0.*$/, '');
			assert.equal(name, 'test-file.txt');

			// Check mode, size, and magic
			const sizeOctal = tarBuf
				.subarray(124, 136)
				.toString('utf8')
				.replace(/\0.*$/, '')
				.trim();
			assert.equal(parseInt(sizeOctal, 8), 14);

			const magic = tarBuf.subarray(257, 263).toString('utf8');
			assert.ok(magic.startsWith('ustar'));

			// Check content at offset 512
			const content = tarBuf.subarray(512, 512 + 14).toString('utf8');
			assert.equal(content, 'hello tar pack');

			// Check padding between 512+14 and 1024
			const padding = tarBuf.subarray(512 + 14, 1024);
			assert.deepEqual(padding, Buffer.alloc(512 - 14, 0));

			resolve();
		} catch (err) {
			reject(err);
		}
	});
	pack.on('error', reject);

	pack.entry(
		{ name: 'test-file.txt', mode: 0o644, mtime: new Date(1700000000000) },
		'hello tar pack',
		(err) => {
			if (err) return reject(err);
			pack.finalize();
		},
	);
});

// 3. pack.entry returns a writable sink stream when payload is omitted and finalizes after streaming exactly header.size bytes
await new Promise((resolve, reject) => {
	const pack = tar.pack();
	const chunks = [];

	pack.on('data', (chunk) => chunks.push(chunk));
	pack.on('end', () => {
		try {
			const tarBuf = Buffer.concat(chunks);
			assert.equal(tarBuf.length % 512, 0);

			const name = tarBuf
				.subarray(0, 100)
				.toString('utf8')
				.replace(/\0.*$/, '');
			assert.equal(name, 'streamed.txt');

			const content = tarBuf.subarray(512, 512 + 11).toString('utf8');
			assert.equal(content, 'stream-data');
			resolve();
		} catch (err) {
			reject(err);
		}
	});
	pack.on('error', reject);

	const entryStream = pack.entry({ name: 'streamed.txt', size: 11 }, (err) => {
		if (err) return reject(err);
		pack.finalize();
	});

	assert.equal(typeof entryStream.write, 'function');
	entryStream.write(Buffer.from('stream-'));
	entryStream.end(Buffer.from('data'));
});

// 4. pack.entry destroys the pack stream and reports size mismatch when streamed bytes do not match header.size
await new Promise((resolve, reject) => {
	const pack = tar.pack();

	const entryStream = pack.entry({ name: 'mismatch.txt', size: 20 }, (err) => {
		try {
			assert.ok(err instanceof Error);
			assert.match(err.message, /size mismatch/);
			resolve();
		} catch (e) {
			reject(e);
		}
	});

	// Write only 5 bytes instead of declared 20 bytes
	entryStream.write(Buffer.from('short'));
	entryStream.end();
});

// 5. pack.entry throws an error when called while another entry stream is still actively piping
{
	const pack = tar.pack();
	const stream1 = pack.entry({ name: 'first.txt', size: 10 });
	assert.throws(
		() => {
			pack.entry({ name: 'second.txt', size: 5 });
		},
		{
			name: 'Error',
			message: /already piping an entry/,
		},
	);
	stream1.destroy();
}

// 6. pack.entry writes directory entries with type directory, default 0755 mode, zero size, and returns a void sink
await new Promise((resolve, reject) => {
	const pack = tar.pack();
	const chunks = [];

	pack.on('data', (chunk) => chunks.push(chunk));
	pack.on('end', () => {
		try {
			const tarBuf = Buffer.concat(chunks);
			const name = tarBuf
				.subarray(0, 100)
				.toString('utf8')
				.replace(/\0.*$/, '');
			assert.equal(name, 'some-dir/');

			const modeOctal = tarBuf
				.subarray(100, 108)
				.toString('utf8')
				.replace(/\0.*$/, '')
				.trim();
			assert.equal(parseInt(modeOctal, 8), 0o755);

			const typeflag = String.fromCharCode(tarBuf[156]);
			assert.equal(typeflag, '5'); // '5' is directory in POSIX tar

			const sizeOctal = tarBuf
				.subarray(124, 136)
				.toString('utf8')
				.replace(/\0.*$/, '')
				.trim();
			assert.equal(parseInt(sizeOctal, 8), 0);

			resolve();
		} catch (err) {
			reject(err);
		}
	});
	pack.on('error', reject);

	let voidErrorCaught = false;
	const voidSink = pack.entry({ name: 'some-dir/', type: 'directory' }, (err) => {
		if (err) return reject(err);
		pack.finalize();
	});

	voidSink.on('error', (err) => {
		assert.match(err.message, /No body allowed for this entry/);
		voidErrorCaught = true;
	});

	// Writing to void sink triggers error event
	voidSink.write(Buffer.from('unexpected'));
	assert.equal(voidErrorCaught, true);
});

Seeder de origen

anónimo