CodeSampleX

Пример

adm-zip 0.6.1

Проверенный пример — npm adm-zip 0.6.1. Контракт выполнен на node 22 · linux debian/x64 · docker и пройден: AdmZip creates an in-memory zip archive and adds…

sha256:03dd301bd633ef294815fa8e88247ec4d0489bce941cb14df11986713cedc4c2

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

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

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

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

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

Окружение Контракт Этапы Запуск
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-16

Кейс

HOW
Цель
verify pkg:npm/adm-zip@0.6.1
Пакеты
Окружение
node 22.23.2
Создан
2026-09-16T11:04:16Z

Контракт

  1. AdmZip creates an in-memory zip archive and adds file entries
  2. readAsText retrieves decompressed file contents as string
  3. getEntry returns entry metadata and getData returns raw decompressed Buffer
  4. nested file entry preserves byte-for-byte binary content
  5. serialize archive to buffer and reload into new AdmZip instance
  6. deleteFile removes an entry from the archive

Файлы

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

Скачать артефакт с исходным кодом (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 pkg:npm/adm-zip@0.6.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/adm-zip@0.6.1

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:db6f5c987450b115cc734dafcd8125568af3d52652fac5b7ba660c3029f15afa","contract":["AdmZip creates an in-memory zip archive and adds file entries","readAsText retrieves decompressed file contents as string","getEntry returns entry metadata and getData returns raw decompressed Buffer","nested file entry preserves byte-for-byte binary content","serialize archive to buffer and reload into new AdmZip instance","deleteFile removes an entry from the archive"],"goal":"verify pkg:npm/adm-zip@0.6.1","kind":"HOW","packages":["pkg:npm/adm-zip@0.6.1"],"schemaVersion":1},"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/adm-zip@0.6.1"],"schemaVersion":1,"subject":"pkg:npm/adm-zip@0.6.1","verifierAdapter":"node-typescript@1"}
index.js
const AdmZip = require('adm-zip');

/**
 * Creates an in-memory zip archive with initial files.
 * @param {Array<{path: string, content: Buffer|string, comment?: string}>} files
 * @returns {AdmZip}
 */
function createArchive(files = []) {
  const zip = new AdmZip();
  for (const file of files) {
    const data = Buffer.isBuffer(file.content)
      ? file.content
      : Buffer.from(file.content, 'utf8');
    zip.addFile(file.path, data, file.comment || '');
  }
  return zip;
}

/**
 * Reads entry content as text.
 * @param {AdmZip} zip
 * @param {string} entryPath
 * @returns {string}
 */
function readEntryText(zip, entryPath) {
  return zip.readAsText(entryPath);
}

/**
 * Serializes archive to a Buffer and reloads a fresh AdmZip instance.
 * @param {AdmZip} zip
 * @returns {AdmZip}
 */
function reloadArchive(zip) {
  const buffer = zip.toBuffer();
  return new AdmZip(buffer);
}

module.exports = {
  AdmZip,
  createArchive,
  readEntryText,
  reloadArchive
};
package-lock.json
{
  "name": "sample-adm-zip",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-adm-zip",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "adm-zip": "0.6.1"
      }
    },
    "node_modules/adm-zip": {
      "version": "0.6.1",
      "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.6.1.tgz",
      "integrity": "sha512-Xwrja8nx9e5o2N1my4DsKCeKpdrnACyr1wtbPxBDgGzKzKyE9kRtBFA8mWldI+RVlD7CBZNWY/wQ2+ydwOR6kQ==",
      "license": "MIT",
      "engines": {
        "node": ">=14.0"
      }
    }
  }
}
package.json
{
  "name": "sample-adm-zip",
  "version": "1.0.0",
  "description": "Clean-room sample verifying pkg:npm/adm-zip@0.6.1 functionality",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "adm-zip": "0.6.1"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/adm-zip@0.6.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/adm-zip@0.6.1"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import AdmZip from 'adm-zip';
import { createArchive, readEntryText, reloadArchive } from '../index.js';

// 1. AdmZip creates an in-memory zip archive and adds file entries
const testContent = 'Hello CodeSampleX adm-zip verification!';
const binaryData = Buffer.from([0x50, 0x4b, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04]);
const zip = createArchive([
  { path: 'test.txt', content: testContent, comment: 'test comment' },
  { path: 'nested/binary.bin', content: binaryData }
]);

assert.strictEqual(zip.getEntries().length, 2, 'zip should contain 2 entries');

// 2. readAsText retrieves decompressed file contents as string
const text = readEntryText(zip, 'test.txt');
assert.strictEqual(text, testContent, 'readAsText should return exact text content');

// 3. getEntry returns entry metadata and getData returns raw decompressed Buffer
const entry = zip.getEntry('test.txt');
assert.ok(entry, 'entry should exist');
assert.strictEqual(entry.entryName, 'test.txt', 'entryName should match');
assert.strictEqual(entry.comment, 'test comment', 'comment should match');
const buffer = entry.getData();
assert.ok(Buffer.isBuffer(buffer), 'getData should return a Buffer');
assert.strictEqual(buffer.toString('utf8'), testContent, 'buffer content should match testContent');

// 4. nested file entry preserves byte-for-byte binary content
const binEntry = zip.getEntry('nested/binary.bin');
assert.ok(binEntry, 'nested entry should exist');
assert.ok(binEntry.getData().equals(binaryData), 'binary data should be byte-identical');

// 5. serialize archive to buffer and reload into new AdmZip instance
const reloaded = reloadArchive(zip);
assert.strictEqual(reloaded.getEntries().length, 2, 'reloaded zip should contain 2 entries');
assert.strictEqual(reloaded.readAsText('test.txt'), testContent, 'reloaded readAsText should match');
assert.ok(reloaded.getEntry('nested/binary.bin').getData().equals(binaryData), 'reloaded binary data should match');

// 6. deleteFile removes an entry from the archive
reloaded.deleteFile('test.txt');
assert.strictEqual(reloaded.getEntries().length, 1, 'archive should have 1 entry after deletion');
assert.strictEqual(reloaded.getEntry('test.txt'), null, 'deleted entry should be null');

console.log('Contract assertions passed.');

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

аноним