CodeSampleX

샘플

get-stream 5.2.0: buffer

검증된 샘플 — npm get-stream 5.2.0: buffer. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: getStream.buffer concatenates buffer chunks from a…

sha256:d142077e41fde9f63a81767ce2bef092986316242ba969e819b51e9fe6c80c1a

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

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 npm

검증 실행 환경

환경 컨트랙트 단계 실행일
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 get-stream.buffer in pkg:npm/get-stream@5.2.0
패키지
심벌
  • get-stream.buffer
생성일
2026-08-23T13:28:03Z

컨트랙트

  1. getStream.buffer concatenates buffer chunks from a readable stream into a single Buffer
  2. getStream.buffer converts string stream chunks into a single Buffer
  3. getStream.buffer resolves to an empty Buffer when given an empty stream
  4. getStream.buffer rejects with MaxBufferError when buffered data exceeds the maxBuffer option limit
  5. getStream.buffer rejects with the emitted error when the stream encounters an error
  6. getStream.buffer rejects with an error when called without a stream argument

파일

  • 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 get-stream.buffer in pkg:npm/get-stream@5.2.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/get-stream@5.2.0
Demonstrate these symbols/APIs:
  - get-stream.buffer

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:95d8fb8135de06a7fca407be1b6b5912cf37293c0920f31a5a28a11272de9b5f","contract":["getStream.buffer concatenates buffer chunks from a readable stream into a single Buffer","getStream.buffer converts string stream chunks into a single Buffer","getStream.buffer resolves to an empty Buffer when given an empty stream","getStream.buffer rejects with MaxBufferError when buffered data exceeds the maxBuffer option limit","getStream.buffer rejects with the emitted error when the stream encounters an error","getStream.buffer rejects with an error when called without a stream argument"],"goal":"verify get-stream.buffer in pkg:npm/get-stream@5.2.0","kind":"HOW","packages":["pkg:npm/get-stream@5.2.0"],"schemaVersion":1,"symbols":["get-stream.buffer"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/get-stream@5.2.0"],"schemaVersion":1,"subject":"pkg:npm/get-stream@5.2.0","symbols":["get-stream.buffer"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-get-stream-buffer",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-get-stream-buffer",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "get-stream": "5.2.0"
      }
    },
    "node_modules/end-of-stream": {
      "version": "1.4.5",
      "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.5.tgz",
      "integrity": "sha512-ooEGc6HP26xXq/N+GCGOT0JKCLDGrq2bQUZrQ7gyrJiZANJ/8YDTxTpQBXGMn+WbIQXNVpyWymm7KYVICQnyOg==",
      "license": "MIT",
      "dependencies": {
        "once": "^1.4.0"
      }
    },
    "node_modules/get-stream": {
      "version": "5.2.0",
      "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz",
      "integrity": "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==",
      "license": "MIT",
      "dependencies": {
        "pump": "^3.0.0"
      },
      "engines": {
        "node": ">=8"
      },
      "funding": {
        "url": "https://github.com/sponsors/sindresorhus"
      }
    },
    "node_modules/once": {
      "version": "1.4.0",
      "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
      "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",
      "license": "ISC",
      "dependencies": {
        "wrappy": "1"
      }
    },
    "node_modules/pump": {
      "version": "3.0.4",
      "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.4.tgz",
      "integrity": "sha512-VS7sjc6KR7e1ukRFhQSY5LM2uBWAUPiOPa/A3mkKmiMwSmRFUITt0xuj+/lesgnCv+dPIEYlkzrcyXgquIHMcA==",
      "license": "MIT",
      "dependencies": {
        "end-of-stream": "^1.1.0",
        "once": "^1.3.1"
      }
    },
    "node_modules/wrappy": {
      "version": "1.0.2",
      "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
      "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
      "license": "ISC"
    }
  }
}
package.json
{
  "name": "sample-get-stream-buffer",
  "version": "1.0.0",
  "private": true,
  "license": "MIT-0",
  "main": "src/index.js",
  "dependencies": {
    "get-stream": "5.2.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify get-stream.buffer in pkg:npm/get-stream@5.2.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/get-stream@5.2.0"
  ],
  "symbols": [
    "get-stream.buffer"
  ]
}
src/index.js
const getStream = require('get-stream');

/**
 * Reads a stream into a single Buffer using getStream.buffer.
 *
 * @param {import('node:stream').Readable} stream - Readable stream to consume.
 * @param {object} [options] - Options passed to get-stream.
 * @returns {Promise<Buffer>} Promise resolving to the combined Buffer.
 */
async function getStreamAsBuffer(stream, options) {
  return getStream.buffer(stream, options);
}

/**
 * Reads a stream with a maximum buffer size constraint.
 *
 * @param {import('node:stream').Readable} stream - Readable stream to consume.
 * @param {number} maxBuffer - Maximum allowed byte length.
 * @returns {Promise<Buffer>} Promise resolving to the combined Buffer.
 */
async function readBufferWithLimit(stream, maxBuffer) {
  return getStream.buffer(stream, { maxBuffer });
}

module.exports = {
  getStream,
  getStreamAsBuffer,
  readBufferWithLimit,
  MaxBufferError: getStream.MaxBufferError,
};
test/contract.mjs
import assert from 'node:assert/strict';
import { Readable } from 'node:stream';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const getStream = require('get-stream');
const {
  getStreamAsBuffer,
  readBufferWithLimit,
  MaxBufferError
} = require('../src/index.js');

async function testBufferFromBufferStream() {
  const buf1 = Buffer.from('hello ');
  const buf2 = Buffer.from('world');
  const stream = Readable.from([buf1, buf2]);
  const result = await getStream.buffer(stream);
  assert.ok(Buffer.isBuffer(result), 'result must be a Buffer');
  assert.deepStrictEqual(result, Buffer.from('hello world'), 'should concatenate buffer chunks into a single Buffer');

  const stream2 = Readable.from([Buffer.from('helper-test')]);
  const helperResult = await getStreamAsBuffer(stream2);
  assert.ok(Buffer.isBuffer(helperResult));
  assert.deepStrictEqual(helperResult, Buffer.from('helper-test'), 'helper should return combined buffer');
}

async function testBufferFromStringStream() {
  const stream = Readable.from(['chunk1', 'chunk2']);
  const result = await getStream.buffer(stream);
  assert.ok(Buffer.isBuffer(result), 'result must be a Buffer');
  assert.deepStrictEqual(result, Buffer.from('chunk1chunk2'), 'should convert string chunks into a single Buffer');
}

async function testEmptyStream() {
  const stream = Readable.from([]);
  const result = await getStream.buffer(stream);
  assert.ok(Buffer.isBuffer(result), 'result must be a Buffer');
  assert.strictEqual(result.length, 0, 'empty stream should resolve to empty Buffer');
  assert.deepStrictEqual(result, Buffer.alloc(0), 'empty stream should equal Buffer.alloc(0)');
}

async function testMaxBufferLimit() {
  const stream = Readable.from([Buffer.from('12345'), Buffer.from('67890')]);
  await assert.rejects(
    async () => {
      await getStream.buffer(stream, { maxBuffer: 8 });
    },
    (err) => {
      assert.ok(err instanceof MaxBufferError || err.name === 'MaxBufferError', 'should be MaxBufferError');
      assert.strictEqual(err.message, 'maxBuffer exceeded');
      return true;
    }
  );

  const stream2 = Readable.from([Buffer.from('too long data')]);
  await assert.rejects(
    async () => {
      await readBufferWithLimit(stream2, 4);
    },
    (err) => {
      assert.ok(err instanceof MaxBufferError || err.name === 'MaxBufferError', 'should be MaxBufferError');
      assert.strictEqual(err.message, 'maxBuffer exceeded');
      return true;
    }
  );
}

async function testStreamError() {
  const customError = new Error('simulated stream error');
  const stream = new Readable({
    read() {
      this.destroy(customError);
    }
  });

  await assert.rejects(
    async () => {
      await getStream.buffer(stream);
    },
    (err) => {
      assert.strictEqual(err, customError, 'should reject with the emitted stream error');
      return true;
    }
  );
}

async function testMissingStream() {
  await assert.rejects(
    async () => {
      await getStream.buffer(null);
    },
    {
      message: 'Expected a stream'
    }
  );

  await assert.rejects(
    async () => {
      await getStreamAsBuffer(undefined);
    },
    {
      message: 'Expected a stream'
    }
  );
}

async function runAll() {
  await testBufferFromBufferStream();
  await testBufferFromStringStream();
  await testEmptyStream();
  await testMaxBufferLimit();
  await testStreamError();
  await testMissingStream();
  console.log('All get-stream.buffer contract tests passed successfully.');
}

await runAll();

오리진 시더

익명