CodeSampleX

Пример

tar 6.2.1: c

Проверенный пример — npm tar 6.2.1: c. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден: tar.c creates a tar archive synchronously when…

sha256:d6a5b7e42ab68c72c740ce26691a58f1cd892ca53e3f1e0c705b8687f5c570ec

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда linux 24 · ubuntu · glibc 2.39 x64 npm

Среды запусков проверки

Окружение Контракт Этапы Запуск
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-29

Кейс

HOW
Цель
verify tar.c in pkg:npm/tar@6.2.1
Пакеты
Символы
  • tar.c
Создан
2026-08-29T05:55:09Z

Контракт

  1. tar.c creates a tar archive synchronously when sync option is enabled
  2. tar.c creates a gzip-compressed tar archive asynchronously returning a Promise
  3. tar.c returns a readable stream emitting tar archive chunks when file option is omitted

Файлы

  • PROMPT.md
  • csx.json
  • index.js
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.cjs

Скачать артефакт с исходным кодом (tar.gz)

Исходный код

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.c in pkg:npm/tar@6.2.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/tar@6.2.1
Demonstrate these symbols/APIs:
  - tar.c

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:0f73923c41ff2258a8ee1d01c9b51b3350fca1ade0c8c83f31c365f0d2f408ad","contract":["tar.c creates a tar archive synchronously when sync option is enabled","tar.c creates a gzip-compressed tar archive asynchronously returning a Promise","tar.c returns a readable stream emitting tar archive chunks when file option is omitted"],"goal":"verify tar.c in pkg:npm/tar@6.2.1","kind":"HOW","packages":["pkg:npm/tar@6.2.1"],"schemaVersion":1,"symbols":["tar.c"]},"contractCommand":["node","test/contract.cjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/tar@6.2.1"],"schemaVersion":1,"subject":"pkg:npm/tar@6.2.1","symbols":["tar.c"],"verifierAdapter":"node-typescript@1"}
index.js
'use strict';

const tar = require('tar');

function createArchiveSync(options, fileList) {
  return tar.c(Object.assign({ sync: true }, options), fileList);
}

async function createArchiveAsync(options, fileList) {
  return await tar.c(options, fileList);
}

function createArchiveStream(options, fileList) {
  return tar.c(options, fileList);
}

module.exports = {
  createArchiveSync,
  createArchiveAsync,
  createArchiveStream,
  tar
};
package-lock.json
{
  "name": "sample-tar-create",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-tar-create",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "tar": "6.2.1"
      }
    },
    "node_modules/chownr": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz",
      "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==",
      "license": "ISC",
      "engines": {
        "node": ">=10"
      }
    },
    "node_modules/fs-minipass": {
      "version": "2.1.0",
      "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz",
      "integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==",
      "license": "ISC",
      "dependencies": {
        "minipass": "^3.0.0"
      },
      "engines": {
        "node": ">= 8"
      }
    },
    "node_modules/fs-minipass/node_modules/minipass": {
      "version": "3.3.6",
      "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz",
      "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==",
      "license": "ISC",
      "dependencies": {
        "yallist": "^4.0.0"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/minipass": {
      "version": "5.0.0",
      "resolved": "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz",
      "integrity": "sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ==",
      "license": "ISC",
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/minizlib": {
      "version": "2.1.2",
      "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz",
      "integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==",
      "license": "MIT",
      "dependencies": {
        "minipass": "^3.0.0",
        "yallist": "^4.0.0"
      },
      "engines": {
        "node": ">= 8"
      }
    },
    "node_modules/minizlib/node_modules/minipass": {
      "version": "3.3.6",
      "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz",
      "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==",
      "license": "ISC",
      "dependencies": {
        "yallist": "^4.0.0"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/mkdirp": {
      "version": "1.0.4",
      "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
      "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==",
      "license": "MIT",
      "bin": {
        "mkdirp": "bin/cmd.js"
      },
      "engines": {
        "node": ">=10"
      }
    },
    "node_modules/tar": {
      "version": "6.2.1",
      "resolved": "https://registry.npmjs.org/tar/-/tar-6.2.1.tgz",
      "integrity": "sha512-DZ4yORTwrbTj/7MZYq2w+/ZFdI6OZ/f9SFHR+71gIVUZhOQPHzVCLpvRnPgyaMpfWxxk/4ONva3GQSyNIKRv6A==",
      "deprecated": "Old versions of tar are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me",
      "license": "ISC",
      "dependencies": {
        "chownr": "^2.0.0",
        "fs-minipass": "^2.0.0",
        "minipass": "^5.0.0",
        "minizlib": "^2.1.1",
        "mkdirp": "^1.0.3",
        "yallist": "^4.0.0"
      },
      "engines": {
        "node": ">=10"
      }
    },
    "node_modules/yallist": {
      "version": "4.0.0",
      "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
      "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
      "license": "ISC"
    }
  }
}
package.json
{
  "name": "sample-tar-create",
  "version": "1.0.0",
  "private": true,
  "description": "verify tar.c in pkg:npm/tar@6.2.1",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.cjs"
  },
  "dependencies": {
    "tar": "6.2.1"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify tar.c in pkg:npm/tar@6.2.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/tar@6.2.1"
  ],
  "symbols": [
    "tar.c"
  ]
}
test/contract.cjs
'use strict';

const assert = require('assert');
const fs = require('fs');
const path = require('path');
const os = require('os');
const tar = require('tar');
const {
  createArchiveSync,
  createArchiveAsync,
  createArchiveStream
} = require('../index.js');

async function run() {
  const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'tar-c-contract-test-'));
  const sourceDir = path.join(tmpDir, 'src');
  fs.mkdirSync(sourceDir, { recursive: true });

  const file1 = path.join(sourceDir, 'file1.txt');
  const file2 = path.join(sourceDir, 'file2.txt');
  fs.writeFileSync(file1, 'Hello CodeSampleX!', 'utf8');
  fs.writeFileSync(file2, 'Archive testing payload.', 'utf8');

  try {
    // 1. Synchronous tar archive creation using tar.c
    const syncTarPath = path.join(tmpDir, 'archive-sync.tar');
    tar.c(
      {
        sync: true,
        file: syncTarPath,
        cwd: sourceDir
      },
      ['file1.txt', 'file2.txt']
    );

    assert(fs.existsSync(syncTarPath), 'Synchronous tar file must be created');
    assert(fs.statSync(syncTarPath).size > 0, 'Synchronous tar file must not be empty');

    const syncEntries = [];
    tar.t({
      sync: true,
      file: syncTarPath,
      onentry: (entry) => syncEntries.push(entry.path)
    });
    assert.deepStrictEqual(syncEntries, ['file1.txt', 'file2.txt'], 'Synchronous tar file must contain expected entries');

    // 2. Asynchronous tar archive creation with gzip using tar.c
    const asyncTgzPath = path.join(tmpDir, 'archive-async.tgz');
    await tar.c(
      {
        gzip: true,
        file: asyncTgzPath,
        cwd: sourceDir
      },
      ['file1.txt']
    );

    assert(fs.existsSync(asyncTgzPath), 'Asynchronous gzip tar file must be created');
    assert(fs.statSync(asyncTgzPath).size > 0, 'Asynchronous gzip tar file must not be empty');

    const asyncEntries = [];
    tar.t({
      sync: true,
      file: asyncTgzPath,
      onentry: (entry) => asyncEntries.push(entry.path)
    });
    assert.deepStrictEqual(asyncEntries, ['file1.txt'], 'Asynchronous gzip tar file must contain expected entry');

    // 3. Readable stream tar archive creation using tar.c
    const stream = tar.c({ cwd: sourceDir }, ['file2.txt']);
    const chunks = [];
    for await (const chunk of stream) {
      chunks.push(chunk);
    }
    const streamBuffer = Buffer.concat(chunks);
    assert(streamBuffer.length > 0, 'Stream buffer must contain tar data');

    // 4. Verify helper functions from index.js
    const helperSyncTar = path.join(tmpDir, 'helper-sync.tar');
    createArchiveSync({ file: helperSyncTar, cwd: sourceDir }, ['file1.txt']);
    assert(fs.existsSync(helperSyncTar), 'Helper synchronous tar file must be created');

    const helperAsyncTgz = path.join(tmpDir, 'helper-async.tgz');
    await createArchiveAsync({ gzip: true, file: helperAsyncTgz, cwd: sourceDir }, ['file2.txt']);
    assert(fs.existsSync(helperAsyncTgz), 'Helper asynchronous tgz file must be created');

    const helperStream = createArchiveStream({ cwd: sourceDir }, ['file1.txt']);
    let helperBytes = 0;
    for await (const chunk of helperStream) {
      helperBytes += chunk.length;
    }
    assert(helperBytes > 0, 'Helper stream must emit bytes');

    console.log('Contract tests passed successfully.');
    process.exit(0);
  } finally {
    try {
      if (fs.existsSync(tmpDir)) {
        fs.rmSync(tmpDir, { recursive: true, force: true });
      }
    } catch (e) {
      // Ignore cleanup error
    }
  }
}

run().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

Исходный сидер

аноним