CodeSampleX

示例

fflate 0.8.3: zipSync

已验证示例 — npm fflate 0.8.3: zipSync. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: zipSync(data) compresses single file Uint8Array into valid ZIP…

sha256:dc564d97d463db24b50f62a6ed7b3c4ce33d87c7586d5d4cf9d1c4d9a8224176

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 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');
}

原始种子者

匿名