CodeSampleX

Exemple

adm-zip 0.6.0: ZipEntry.entryName

Échantillon vérifié pour npm adm-zip 0.6.0: ZipEntry.entryName. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi : ZipEntry…

sha256:519d1a1f0b78f4f0062a445fe9eede8c8e87a203beed7e851d02cf1f71b74752

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-21

Cas

HOW
Objectif
verify ZipEntry.entryName in pkg:npm/adm-zip@0.6.0
Paquets
Symboles
  • ZipEntry.entryName
Environnement
node 22.23.2
Créé
2026-08-21T11:14:47Z

Contrat

  1. ZipEntry exposes entryName getter returning relative archive path
  2. entryName reflects directory paths ending with forward slash
  3. ZipEntry exposes entryName setter allowing in-place renaming of entries
  4. setting entryName ending with slash updates isDirectory property
  5. serializing archive to buffer preserves renamed entryName upon reload
  6. retrieving content via readAsText and getEntry functions with updated entryName

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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 ZipEntry.entryName in pkg:npm/adm-zip@0.6.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/adm-zip@0.6.0
Demonstrate these symbols/APIs:
  - ZipEntry.entryName
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.
csx.json
{"case":{"caseId":"case:sha256:8ea0ecb9a40788b0b3c9228a348710b4d415c00e54e1625757b3fcccb5194b72","constraints":{"executionContext":"node"},"contract":["ZipEntry exposes entryName getter returning relative archive path","entryName reflects directory paths ending with forward slash","ZipEntry exposes entryName setter allowing in-place renaming of entries","setting entryName ending with slash updates isDirectory property","serializing archive to buffer preserves renamed entryName upon reload","retrieving content via readAsText and getEntry functions with updated entryName"],"goal":"verify ZipEntry.entryName in pkg:npm/adm-zip@0.6.0","kind":"HOW","packages":["pkg:npm/adm-zip@0.6.0"],"schemaVersion":1,"symbols":["ZipEntry.entryName"]},"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/adm-zip@0.6.0"],"schemaVersion":1,"subject":"pkg:npm/adm-zip@0.6.0","symbols":["ZipEntry.entryName"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-adm-zip-entryname",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-adm-zip-entryname",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "adm-zip": "0.6.0"
      }
    },
    "node_modules/adm-zip": {
      "version": "0.6.0",
      "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.6.0.tgz",
      "integrity": "sha512-XleryMhbuksdKtofnWZ9Sk+4CUTbms4Mb/EU32SZwToAyZ5RgVos/ki8n+yr0LWHOGKuakbXTuuYNHLQjhddgg==",
      "license": "MIT",
      "engines": {
        "node": ">=14.0"
      }
    }
  }
}
package.json
{
  "name": "sample-adm-zip-entryname",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for ZipEntry.entryName in adm-zip",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "adm-zip": "0.6.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify ZipEntry.entryName in pkg:npm/adm-zip@0.6.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/adm-zip@0.6.0"
  ],
  "symbols": [
    "ZipEntry.entryName"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const AdmZip = require('adm-zip');

/**
 * Retrieves all entryName values from an AdmZip archive.
 * @param {AdmZip} zip - Source AdmZip instance.
 * @returns {string[]} Array of entry names.
 */
function listEntryNames(zip) {
  return zip.getEntries().map((entry) => entry.entryName);
}

/**
 * Finds a ZipEntry by its exact entryName.
 * @param {AdmZip} zip - Source AdmZip instance.
 * @param {string} entryName - Target entry name.
 * @returns {any} The matching ZipEntry or undefined.
 */
function findEntryByName(zip, entryName) {
  return zip.getEntries().find((entry) => entry.entryName === entryName);
}

/**
 * Renames an entry by modifying its entryName property.
 * @param {any} entry - The ZipEntry to rename.
 * @param {string} newName - New entry name.
 * @returns {any} The updated ZipEntry.
 */
function renameEntry(entry, newName) {
  entry.entryName = newName;
  return entry;
}

/**
 * Creates an AdmZip archive with sample entries.
 * @param {Array<{path: string, content: Buffer|string}>} files - File definitions.
 * @returns {AdmZip} Initialized AdmZip archive.
 */
function createArchive(files) {
  const zip = new AdmZip();
  for (const file of files) {
    const buffer = Buffer.isBuffer(file.content)
      ? file.content
      : Buffer.from(file.content, 'utf8');
    zip.addFile(file.path, buffer);
  }
  return zip;
}

/**
 * Serializes an archive to buffer and re-instantiates an AdmZip instance.
 * @param {AdmZip} zip - Source AdmZip instance.
 * @returns {AdmZip} Reloaded AdmZip instance.
 */
function reloadArchive(zip) {
  const buffer = zip.toBuffer();
  return new AdmZip(buffer);
}

module.exports = {
  AdmZip,
  listEntryNames,
  findEntryByName,
  renameEntry,
  createArchive,
  reloadArchive
};
test/contract.js
const assert = require('node:assert');
const AdmZip = require('adm-zip');
const {
  listEntryNames,
  findEntryByName,
  renameEntry,
  createArchive,
  reloadArchive
} = require('../src/index.js');

// Initialize archive with file and directory entries
const zip = createArchive([
  { path: 'docs/readme.txt', content: 'Documentation content' },
  { path: 'data/config.json', content: JSON.stringify({ version: '1.0' }) },
  { path: 'images/', content: '' }
]);

const entries = zip.getEntries();
assert.strictEqual(entries.length, 3, 'Archive should contain 3 entries');

// 1. ZipEntry exposes entryName getter returning relative archive path
const docEntry = findEntryByName(zip, 'docs/readme.txt');
assert.ok(docEntry, 'Entry with name docs/readme.txt should exist');
assert.strictEqual(typeof docEntry.entryName, 'string', 'entryName should be a string');
assert.strictEqual(docEntry.entryName, 'docs/readme.txt', 'entryName should return the relative path');

// 2. entryName reflects directory paths ending with forward slash
const dirEntry = findEntryByName(zip, 'images/');
assert.ok(dirEntry, 'Directory entry images/ should exist');
assert.strictEqual(dirEntry.entryName, 'images/', 'entryName of directory should include trailing slash');
assert.strictEqual(dirEntry.isDirectory, true, 'isDirectory should be true for trailing slash entryName');

// 3. ZipEntry exposes entryName setter allowing in-place renaming of entries
renameEntry(docEntry, 'documentation/guide.txt');
assert.strictEqual(docEntry.entryName, 'documentation/guide.txt', 'entryName should be updated after setting');
const updatedNames = listEntryNames(zip);
assert.ok(updatedNames.includes('documentation/guide.txt'), 'listEntryNames should include renamed path');
assert.ok(!updatedNames.includes('docs/readme.txt'), 'listEntryNames should no longer include old path');

// 4. setting entryName ending with slash updates isDirectory property
const configEntry = findEntryByName(zip, 'data/config.json');
assert.ok(configEntry, 'configEntry should exist');
assert.strictEqual(configEntry.isDirectory, false, 'File entry should have isDirectory=false initially');
renameEntry(configEntry, 'data/config_dir/');
assert.strictEqual(configEntry.isDirectory, true, 'Setting entryName with trailing slash should update isDirectory to true');
renameEntry(configEntry, 'data/config.json');
assert.strictEqual(configEntry.isDirectory, false, 'Reverting entryName should update isDirectory to false');

// 5. serializing archive to buffer preserves renamed entryName upon reload
const reloaded = reloadArchive(zip);
const reloadedNames = listEntryNames(reloaded);
assert.ok(reloadedNames.includes('documentation/guide.txt'), 'Reloaded archive should contain renamed entryName');
assert.ok(reloadedNames.includes('data/config.json'), 'Reloaded archive should contain config entryName');
assert.ok(reloadedNames.includes('images/'), 'Reloaded archive should contain images directory entryName');

// 6. retrieving content via readAsText and getEntry functions with updated entryName
assert.strictEqual(reloaded.readAsText('documentation/guide.txt'), 'Documentation content', 'readAsText should return content by updated entryName');
const retrievedEntry = reloaded.getEntry('documentation/guide.txt');
assert.ok(retrievedEntry, 'getEntry should find entry by updated entryName');
assert.strictEqual(retrievedEntry.entryName, 'documentation/guide.txt', 'Retrieved entry entryName should match');

console.log('Contract tests passed successfully.');

Seeder d'origine

anonyme