CodeSampleX

サンプル

minizlib 3.1.0: compress and decompress data using minizlib Gzip and Gunzip streams

検証済みサンプル — npm minizlib 3.1.0: compress and decompress data using minizlib Gzip and Gunzip streams. node 22 · linux alpine/x64 · docker で contract…

sha256:867f0794653070fe38765517c2734750f5bea7d73308b69390c4ffc9efe03ffa

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。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 alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-28

ケース

HOW
ゴール
compress and decompress data using minizlib Gzip and Gunzip streams
パッケージ
シンボル
  • minizlib.Gunzip
  • minizlib.Gzip
環境
node 22.23.2
作成日
2026-08-28T05:35:31Z

コントラクト

  1. Gzip and Gunzip classes are exported and instantiate stream instances extending Zlib
  2. Gzip synchronously compresses string or buffer into gzip formatted buffer with magic bytes 0x1f 0x8b
  3. Gunzip synchronously decompresses gzip buffer back to the original content
  4. Gzip piped into Gunzip processes data through stream pipeline asynchronously
  5. Gunzip raises ZlibError when consuming invalid or corrupted compressed input

ファイル

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

ソースアーティファクトをダウンロード (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: compress and decompress data using minizlib Gzip and Gunzip streams
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/minizlib@3.1.0
Demonstrate these symbols/APIs:
  - minizlib.Gunzip
  - minizlib.Gzip

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:ce021948e986b7e97843d5d9ab7d32dbd600772ddd521e7e2365da2fff5656e7","contract":["Gzip and Gunzip classes are exported and instantiate stream instances extending Zlib","Gzip synchronously compresses string or buffer into gzip formatted buffer with magic bytes 0x1f 0x8b","Gunzip synchronously decompresses gzip buffer back to the original content","Gzip piped into Gunzip processes data through stream pipeline asynchronously","Gunzip raises ZlibError when consuming invalid or corrupted compressed input"],"goal":"compress and decompress data using minizlib Gzip and Gunzip streams","kind":"HOW","packages":["pkg:npm/minizlib@3.1.0"],"schemaVersion":1,"symbols":["minizlib.Gunzip","minizlib.Gzip"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/minizlib@3.1.0"],"schemaVersion":1,"subject":"pkg:npm/minizlib@3.1.0","symbols":["minizlib.Gunzip","minizlib.Gzip"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-minizlib-gzip-gunzip",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-minizlib-gzip-gunzip",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "minizlib": "3.1.0"
      }
    },
    "node_modules/minipass": {
      "version": "7.1.3",
      "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.3.tgz",
      "integrity": "sha512-tEBHqDnIoM/1rXME1zgka9g6Q2lcoCkxHLuc7ODJ5BxbP5d4c2Z5cGgtXAku59200Cx7diuHTOYfSBD8n6mm8A==",
      "license": "BlueOak-1.0.0",
      "engines": {
        "node": ">=16 || 14 >=14.17"
      }
    },
    "node_modules/minizlib": {
      "version": "3.1.0",
      "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-3.1.0.tgz",
      "integrity": "sha512-KZxYo1BUkWD2TVFLr0MQoM8vUUigWD3LlD83a/75BqC+4qE0Hb1Vo5v1FgcfaNXvfXzr+5EhQ6ing/CaBijTlw==",
      "license": "MIT",
      "dependencies": {
        "minipass": "^7.1.2"
      },
      "engines": {
        "node": ">= 18"
      }
    }
  }
}
package.json
{
  "name": "sample-minizlib-gzip-gunzip",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "description": "Clean-room verification for minizlib Gzip and Gunzip streams",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "minizlib": "3.1.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "compress and decompress data using minizlib Gzip and Gunzip streams",
  "kind": "HOW",
  "packages": [
    "pkg:npm/minizlib@3.1.0"
  ],
  "symbols": [
    "minizlib.Gunzip",
    "minizlib.Gzip"
  ]
}
src/index.js
import { Gzip, Gunzip, Zlib, ZlibError } from 'minizlib';

/**
 * Compresses data synchronously using minizlib Gzip.
 * @param {string | Buffer} data
 * @param {import('zlib').ZlibOptions} [options]
 * @returns {Buffer}
 */
export function gzipSync(data, options) {
  const zip = new Gzip(options);
  zip.end(data);
  return zip.read();
}

/**
 * Decompresses gzip data synchronously using minizlib Gunzip.
 * @param {Buffer} data
 * @param {import('zlib').ZlibOptions} [options]
 * @returns {Buffer}
 */
export function gunzipSync(data, options) {
  const unzip = new Gunzip(options);
  unzip.end(data);
  return unzip.read();
}

/**
 * Creates a configured Gzip compression stream.
 * @param {import('zlib').ZlibOptions} [options]
 * @returns {Gzip}
 */
export function createGzipStream(options) {
  return new Gzip(options);
}

/**
 * Creates a configured Gunzip decompression stream.
 * @param {import('zlib').ZlibOptions} [options]
 * @returns {Gunzip}
 */
export function createGunzipStream(options) {
  return new Gunzip(options);
}

export { Gzip, Gunzip, Zlib, ZlibError };
test/contract.js
import assert from 'node:assert/strict';
import {
  Gzip,
  Gunzip,
  Zlib,
  ZlibError,
  gzipSync,
  gunzipSync,
  createGzipStream,
  createGunzipStream,
} from '../src/index.js';

// 1. Gzip and Gunzip classes are exported and instantiate stream instances extending Zlib
assert.equal(typeof Gzip, 'function', 'Gzip must be a constructor function');
assert.equal(typeof Gunzip, 'function', 'Gunzip must be a constructor function');
const gzipInstance = new Gzip();
const gunzipInstance = new Gunzip();
assert.ok(gzipInstance instanceof Zlib, 'Gzip must inherit from Zlib');
assert.ok(gunzipInstance instanceof Zlib, 'Gunzip must inherit from Zlib');

// 2. Gzip synchronously compresses string or buffer into gzip formatted buffer with magic bytes 0x1f 0x8b
const sampleText = 'CodeSampleX minizlib stream contract verification payload 12345';
const compressedBuffer = gzipSync(sampleText);
assert.ok(Buffer.isBuffer(compressedBuffer), 'Compressed output must be a Buffer');
assert.ok(compressedBuffer.length > 0, 'Compressed output must not be empty');
assert.equal(compressedBuffer[0], 0x1f, 'Gzip magic byte 0 must be 0x1f');
assert.equal(compressedBuffer[1], 0x8b, 'Gzip magic byte 1 must be 0x8b');

// 3. Gunzip synchronously decompresses gzip buffer back to the original content
const decompressedBuffer = gunzipSync(compressedBuffer);
assert.ok(Buffer.isBuffer(decompressedBuffer), 'Decompressed output must be a Buffer');
assert.equal(decompressedBuffer.toString('utf8'), sampleText, 'Decompressed text must match original');

// 4. Gzip piped into Gunzip processes data through stream pipeline asynchronously
const zipStream = createGzipStream();
const unzipStream = createGunzipStream();
zipStream.pipe(unzipStream);

const receivedChunks = [];
unzipStream.on('data', chunk => receivedChunks.push(chunk));

await new Promise((resolve, reject) => {
  unzipStream.on('end', () => {
    const pipedResult = Buffer.concat(receivedChunks).toString('utf8');
    assert.equal(pipedResult, sampleText, 'Stream piped result must match original payload');
    resolve();
  });
  zipStream.on('error', reject);
  unzipStream.on('error', reject);
  zipStream.end(sampleText);
});

// 5. Gunzip raises ZlibError when consuming invalid or corrupted compressed input
let caughtError = null;
try {
  gunzipSync(Buffer.from('not valid compressed gzip payload'));
} catch (err) {
  caughtError = err;
}
assert.ok(caughtError !== null, 'Gunzip must throw an error on invalid compressed input');
assert.ok(caughtError instanceof Error, 'Thrown error must be an instance of Error');
assert.ok(
  caughtError instanceof ZlibError || caughtError.code !== undefined || caughtError.message.length > 0,
  'Error must have diagnostic details'
);

console.log('All minizlib contract assertions passed successfully.');

オリジンシーダー

匿名