CodeSampleX

샘플

fflate 0.8.3: zipSync

검증된 샘플 — npm fflate 0.8.3: zipSync. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: zipSync(data) compresses single file Uint8Array into valid…

sha256:dc564d97d463db24b50f62a6ed7b3c4ce33d87c7586d5d4cf9d1c4d9a8224176

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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-19

케이스

HOW
목표
verify fflate.zipSync in pkg:npm/fflate@0.8.3
패키지
심벌
  • fflate.zipSync
환경
node 22.23.2
생성일
2026-09-18T00:06:35Z

컨트랙트

  1. zipSync(data) compresses single file Uint8Array into valid ZIP format returning Uint8Array
  2. zipSync(data) supports multiple files and nested directory paths in archive
  3. zipSync(data, opts) respects compression level option including level 0 uncompressed store
  4. zipSync(data) accepts per-file options tuple [data, opts] with custom compression level
  5. zipSync(data) creates empty ZIP archive when provided empty data mapping
  6. zipSync(data) compresses nested object mapping into hierarchical directory structure

파일

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • 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 fflate.zipSync in pkg:npm/fflate@0.8.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/fflate@0.8.3
Demonstrate these symbols/APIs:
  - fflate.zipSync

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:d6bd5cbd0e992f6be72d2ea47fa48a28cf05734a987c2b124b812453b6d0bea9","contract":["zipSync(data) compresses single file Uint8Array into valid ZIP format returning Uint8Array","zipSync(data) supports multiple files and nested directory paths in archive","zipSync(data, opts) respects compression level option including level 0 uncompressed store","zipSync(data) accepts per-file options tuple [data, opts] with custom compression level","zipSync(data) creates empty ZIP archive when provided empty data mapping","zipSync(data) compresses nested object mapping into hierarchical directory structure"],"goal":"verify fflate.zipSync in pkg:npm/fflate@0.8.3","kind":"HOW","packages":["pkg:npm/fflate@0.8.3"],"schemaVersion":1,"symbols":["fflate.zipSync"]},"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/fflate@0.8.3"],"schemaVersion":1,"subject":"pkg:npm/fflate@0.8.3","symbols":["fflate.zipSync"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-fflate",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-fflate",
      "version": "1.0.0",
      "dependencies": {
        "fflate": "0.8.3"
      }
    },
    "node_modules/fflate": {
      "version": "0.8.3",
      "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.3.tgz",
      "integrity": "sha512-tbZNuJrLwGUp3zshBtdy4W+ORxZuIh8a5ilyIEQDC5rY1f3U20JMry0Ll3WBzU58EZKsEuJFXhb5gwv8CsPvgA==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-fflate",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of fflate.zipSync in pkg:npm/fflate@0.8.3",
  "main": "src/index.js",
  "dependencies": {
    "fflate": "0.8.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify fflate.zipSync in pkg:npm/fflate@0.8.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/fflate@0.8.3"
  ],
  "symbols": [
    "fflate.zipSync"
  ]
}
src/index.js
const {
  zipSync,
  unzipSync,
  strToU8,
  strFromU8
} = require('fflate');

/**
 * Creates a ZIP archive synchronously from a mapping of filenames to file data.
 *
 * @param {Record<string, Uint8Array | [Uint8Array, object] | object>} data - Mapping of filenames/paths to content or nested objects.
 * @param {object} [opts] - Global zip options (e.g. level, mem).
 * @returns {Uint8Array} The compressed ZIP file bytes.
 */
function createZip(data, opts) {
  return zipSync(data, opts);
}

module.exports = {
  createZip,
  zipSync,
  unzipSync,
  strToU8,
  strFromU8
};
test/contract.mjs
import assert from 'node:assert';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  createZip,
  zipSync,
  unzipSync,
  strToU8,
  strFromU8
} = require('../src/index.js');

// 0. Export verification
assert.strictEqual(typeof createZip, 'function', 'createZip must be a function');
assert.strictEqual(typeof zipSync, 'function', 'zipSync must be a function');
assert.strictEqual(typeof unzipSync, 'function', 'unzipSync must be a function');
assert.strictEqual(typeof strToU8, 'function', 'strToU8 must be a function');
assert.strictEqual(typeof strFromU8, 'function', 'strFromU8 must be a function');

// 1. zipSync(data) compresses single file Uint8Array into valid ZIP format returning Uint8Array
{
  const content = strToU8('Hello from CodeSampleX clean-room verification!');
  const archive = zipSync({
    'greeting.txt': content
  });
  assert(archive instanceof Uint8Array, 'archive should be a Uint8Array');
  assert(archive.length > 0, 'archive length should be positive');

  const extracted = unzipSync(archive);
  assert(extracted['greeting.txt'] instanceof Uint8Array, 'extracted greeting.txt should be Uint8Array');
  assert.strictEqual(strFromU8(extracted['greeting.txt']), 'Hello from CodeSampleX clean-room verification!');
}

// 2. zipSync(data) supports multiple files and nested directory paths in archive
{
  const files = {
    'docs/readme.txt': strToU8('Documentation overview'),
    'src/main.js': strToU8('console.log(42);'),
    'LICENSE': strToU8('MIT-0')
  };
  const archive = zipSync(files);
  assert(archive instanceof Uint8Array);

  const extracted = unzipSync(archive);
  assert.strictEqual(Object.keys(extracted).length, 3);
  assert.strictEqual(strFromU8(extracted['docs/readme.txt']), 'Documentation overview');
  assert.strictEqual(strFromU8(extracted['src/main.js']), 'console.log(42);');
  assert.strictEqual(strFromU8(extracted['LICENSE']), 'MIT-0');
}

// 3. zipSync(data, opts) respects compression level option including level 0 uncompressed store
{
  const repetitiveText = 'A'.repeat(5000);
  const data = { 'data.txt': strToU8(repetitiveText) };

  const storeArchive = zipSync(data, { level: 0 });
  const compressedArchive = zipSync(data, { level: 9 });

  assert(storeArchive.length > compressedArchive.length, 'level 0 should be larger than level 9 on repetitive data');

  const uncompressedStore = unzipSync(storeArchive);
  assert.strictEqual(strFromU8(uncompressedStore['data.txt']), repetitiveText);

  const uncompressedCompressed = unzipSync(compressedArchive);
  assert.strictEqual(strFromU8(uncompressedCompressed['data.txt']), repetitiveText);
}

// 4. zipSync(data) accepts per-file options tuple [data, opts] with custom compression level
{
  const payload1 = strToU8('B'.repeat(2000));
  const payload2 = strToU8('C'.repeat(2000));

  const archive = zipSync({
    'stored.txt': [payload1, { level: 0 }],
    'compressed.txt': [payload2, { level: 6 }]
  });

  const extracted = unzipSync(archive);
  assert.strictEqual(strFromU8(extracted['stored.txt']), 'B'.repeat(2000));
  assert.strictEqual(strFromU8(extracted['compressed.txt']), 'C'.repeat(2000));
}

// 5. zipSync(data) creates empty ZIP archive when provided empty data mapping
{
  const emptyArchive = zipSync({});
  assert(emptyArchive instanceof Uint8Array, 'empty archive should be Uint8Array');
  assert(emptyArchive.length >= 22, 'empty ZIP file has at least 22 bytes end of central directory record');

  const extracted = unzipSync(emptyArchive);
  assert.deepStrictEqual(extracted, {}, 'extracted empty archive should have no entries');
}

// 6. zipSync(data) compresses nested object mapping into hierarchical directory structure
{
  const tree = {
    folderA: {
      'inner.txt': strToU8('inner content A'),
      folderB: {
        'deep.txt': strToU8('deep content B')
      }
    }
  };

  const archive = zipSync(tree);
  const extracted = unzipSync(archive);

  assert.strictEqual(strFromU8(extracted['folderA/inner.txt']), 'inner content A');
  assert.strictEqual(strFromU8(extracted['folderA/folderB/deep.txt']), 'deep content B');
}

// Also verify createZip wrapper function works identically
{
  const archive = createZip({ 'wrapped.txt': strToU8('wrapped test') });
  const extracted = unzipSync(archive);
  assert.strictEqual(strFromU8(extracted['wrapped.txt']), 'wrapped test');
}

오리진 시더

익명