CodeSampleX

샘플

readable-stream 2.3.8: PassThrough

검증된 샘플 — npm readable-stream 2.3.8: PassThrough. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: PassThrough stream can be instantiated and…

sha256:b33f4ba15f12332a991f05429f6829bd44cbe1009b6a7d830ef92c46d640e710

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

케이스

HOW
목표
verify readable-stream.PassThrough in pkg:npm/readable-stream@2.3.8
패키지
심벌
  • readable-stream.PassThrough
환경
node 22.23.2
생성일
2026-08-23T13:51:13Z

컨트랙트

  1. PassThrough stream can be instantiated and exposes stream methods
  2. PassThrough stream passes written buffer chunks through unmodified in paused mode
  3. PassThrough stream supports flowing mode with data and end events
  4. PassThrough stream supports objectMode for passing non-buffer objects

파일

  • PROMPT.md
  • csx.json
  • index.js
  • package-lock.json
  • package.json
  • spec.json
  • 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: verify readable-stream.PassThrough in pkg:npm/readable-stream@2.3.8
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/readable-stream@2.3.8
Demonstrate these symbols/APIs:
  - readable-stream.PassThrough

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:9a1715e9af134eeb9ee57711b8e5d2ab643019fe06caaa8ced699da81c5ed9b4","contract":["PassThrough stream can be instantiated and exposes stream methods","PassThrough stream passes written buffer chunks through unmodified in paused mode","PassThrough stream supports flowing mode with data and end events","PassThrough stream supports objectMode for passing non-buffer objects"],"goal":"verify readable-stream.PassThrough in pkg:npm/readable-stream@2.3.8","kind":"HOW","packages":["pkg:npm/readable-stream@2.3.8"],"schemaVersion":1,"symbols":["readable-stream.PassThrough"]},"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/readable-stream@2.3.8"],"schemaVersion":1,"subject":"pkg:npm/readable-stream@2.3.8","symbols":["readable-stream.PassThrough"],"verifierAdapter":"node-typescript@1"}
index.js
const { PassThrough } = require('readable-stream');

/**
 * Creates a PassThrough stream instance with optional configuration.
 *
 * @param {object} [options]
 * @returns {PassThrough}
 */
function createPassThrough(options) {
  return new PassThrough(options);
}

/**
 * Feeds an array of chunks into a PassThrough stream and collects the output Buffer.
 *
 * @param {Buffer[]|string[]} chunks
 * @param {object} [options]
 * @returns {Promise<Buffer>}
 */
function passThroughBuffer(chunks, options) {
  return new Promise((resolve, reject) => {
    const pt = new PassThrough(options);
    const collected = [];

    pt.on('data', (chunk) => {
      collected.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
    });

    pt.on('end', () => {
      resolve(Buffer.concat(collected));
    });

    pt.on('error', (err) => {
      reject(err);
    });

    for (const chunk of chunks) {
      pt.write(chunk);
    }
    pt.end();
  });
}

module.exports = {
  PassThrough,
  createPassThrough,
  passThroughBuffer,
};
package-lock.json
{
  "name": "sample-readable-stream-passthrough",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-readable-stream-passthrough",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "readable-stream": "2.3.8"
      }
    },
    "node_modules/core-util-is": {
      "version": "1.0.3",
      "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
      "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==",
      "license": "MIT"
    },
    "node_modules/inherits": {
      "version": "2.0.4",
      "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
      "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
      "license": "ISC"
    },
    "node_modules/isarray": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
      "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==",
      "license": "MIT"
    },
    "node_modules/process-nextick-args": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
      "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==",
      "license": "MIT"
    },
    "node_modules/readable-stream": {
      "version": "2.3.8",
      "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz",
      "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==",
      "license": "MIT",
      "dependencies": {
        "core-util-is": "~1.0.0",
        "inherits": "~2.0.3",
        "isarray": "~1.0.0",
        "process-nextick-args": "~2.0.0",
        "safe-buffer": "~5.1.1",
        "string_decoder": "~1.1.1",
        "util-deprecate": "~1.0.1"
      }
    },
    "node_modules/safe-buffer": {
      "version": "5.1.2",
      "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
      "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
      "license": "MIT"
    },
    "node_modules/string_decoder": {
      "version": "1.1.1",
      "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
      "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
      "license": "MIT",
      "dependencies": {
        "safe-buffer": "~5.1.0"
      }
    },
    "node_modules/util-deprecate": {
      "version": "1.0.2",
      "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
      "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-readable-stream-passthrough",
  "version": "1.0.0",
  "description": "Verify readable-stream PassThrough stream behavior",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "readable-stream": "2.3.8"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify readable-stream.PassThrough in pkg:npm/readable-stream@2.3.8",
  "kind": "HOW",
  "packages": [
    "pkg:npm/readable-stream@2.3.8"
  ],
  "symbols": [
    "readable-stream.PassThrough"
  ]
}
test/contract.js
const assert = require('node:assert');
const { PassThrough, createPassThrough, passThroughBuffer } = require('../index.js');

async function main() {
  // 1. Instantiation and basic interface
  {
    const pt = createPassThrough();
    assert.strictEqual(pt instanceof PassThrough, true);
    assert.strictEqual(typeof pt.write, 'function');
    assert.strictEqual(typeof pt.read, 'function');
    assert.strictEqual(typeof pt.pipe, 'function');
  }

  // 2. Data written is read back unmodified in paused mode
  {
    const pt = new PassThrough();
    const input = Buffer.from('hello-passthrough');
    pt.write(input);
    pt.end();

    const output = pt.read();
    assert.deepStrictEqual(output, input);
  }

  // 3. Flowing mode with data and end events via passThroughBuffer
  {
    const chunks = [
      Buffer.from('alpha-'),
      Buffer.from('beta-'),
      Buffer.from('gamma'),
    ];
    const result = await passThroughBuffer(chunks);
    assert.strictEqual(result.toString('utf8'), 'alpha-beta-gamma');
  }

  // 4. Object mode pass-through
  {
    const pt = new PassThrough({ objectMode: true });
    const collected = [];

    pt.on('data', (item) => {
      collected.push(item);
    });

    pt.write({ key: 'value1' });
    pt.write({ key: 'value2' });
    pt.end();

    await new Promise((resolve) => pt.on('end', resolve));

    assert.strictEqual(collected.length, 2);
    assert.deepStrictEqual(collected[0], { key: 'value1' });
    assert.deepStrictEqual(collected[1], { key: 'value2' });
  }

  console.log('Contract test passed successfully.');
}

main().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

오리진 시더

익명