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

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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');
}

オリジンシーダー

匿名