CodeSampleX

サンプル

get-stream 5.2.0: array

検証済みサンプル — npm get-stream 5.2.0: array. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: getStream.array collects all chunks from an objectMode…

sha256:14dd6f50be13888e0132b4231be61ccd5a8bb42769eb8e81c6d345e520135831

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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.array in pkg:npm/get-stream@5.2.0
パッケージ
シンボル
  • get-stream.array
作成日
2026-08-23T13:26:19Z

コントラクト

  1. getStream.array collects all chunks from an objectMode readable stream into an array of objects
  2. getStream.array collects string stream chunks into an array of strings with specified encoding
  3. getStream.array collects binary stream chunks into an array of Buffer instances
  4. getStream.array resolves to an empty array when given an empty stream
  5. getStream.array rejects with MaxBufferError when buffered data exceeds the maxBuffer option limit
  6. getStream.array rejects with the emitted error when the stream encounters an error
  7. getStream.array 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.array 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.array

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:5726a8a644e0f0016ac57424e6be39d005a9c0049e09114df8e2f74e8da9899f","contract":["getStream.array collects all chunks from an objectMode readable stream into an array of objects","getStream.array collects string stream chunks into an array of strings with specified encoding","getStream.array collects binary stream chunks into an array of Buffer instances","getStream.array resolves to an empty array when given an empty stream","getStream.array rejects with MaxBufferError when buffered data exceeds the maxBuffer option limit","getStream.array rejects with the emitted error when the stream encounters an error","getStream.array rejects with an error when called without a stream argument"],"goal":"verify get-stream.array in pkg:npm/get-stream@5.2.0","kind":"HOW","packages":["pkg:npm/get-stream@5.2.0"],"schemaVersion":1,"symbols":["get-stream.array"]},"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.array"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-get-stream-array",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-get-stream-array",
      "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-array",
  "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.array in pkg:npm/get-stream@5.2.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/get-stream@5.2.0"
  ],
  "symbols": [
    "get-stream.array"
  ]
}
src/index.js
const getStream = require('get-stream');

/**
 * Collects all chunks from a stream into an array using getStream.array.
 *
 * @param {import('node:stream').Readable} stream - Readable stream to consume.
 * @param {object} [options] - Options passed to get-stream.
 * @returns {Promise<any[]>} Promise resolving to an array of chunks.
 */
async function getStreamArray(stream, options) {
  return getStream.array(stream, options);
}

/**
 * Collects items from an object-mode stream into an array.
 *
 * @param {import('node:stream').Readable} stream - Readable stream emitting objects.
 * @param {object} [options] - Options passed to get-stream.
 * @returns {Promise<any[]>} Promise resolving to array of objects.
 */
async function collectObjectStream(stream, options) {
  return getStream.array(stream, options);
}

/**
 * Collects string chunks from a stream into an array of strings.
 *
 * @param {import('node:stream').Readable} stream - Readable stream emitting string data.
 * @param {string} [encoding='utf8'] - Character encoding.
 * @returns {Promise<string[]>} Promise resolving to array of string chunks.
 */
async function collectStringChunks(stream, encoding = 'utf8') {
  return getStream.array(stream, { encoding });
}

/**
 * Collects buffer chunks from a stream into an array of Buffers.
 *
 * @param {import('node:stream').Readable} stream - Readable stream emitting binary buffers.
 * @returns {Promise<Buffer[]>} Promise resolving to array of Buffers.
 */
async function collectBufferChunks(stream) {
  return getStream.array(stream, { encoding: 'buffer' });
}

module.exports = {
  getStream,
  getStreamArray,
  collectObjectStream,
  collectStringChunks,
  collectBufferChunks,
  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 {
  getStreamArray,
  collectObjectStream,
  collectStringChunks,
  collectBufferChunks,
  MaxBufferError
} = require('../src/index.js');

async function testObjectModeStream() {
  const items = [
    { id: 1, name: 'alpha' },
    { id: 2, name: 'beta' },
    { id: 3, name: 'gamma' }
  ];
  const stream = Readable.from(items, { objectMode: true });
  const result = await getStream.array(stream);
  assert.deepStrictEqual(result, items, 'should collect all objects in objectMode');

  const stream2 = Readable.from([{ value: 42 }], { objectMode: true });
  const helperResult = await collectObjectStream(stream2);
  assert.deepStrictEqual(helperResult, [{ value: 42 }], 'helper should collect objects');
}

async function testStringStream() {
  const chunks = ['Hello', ', ', 'world', '!'];
  const stream = Readable.from(chunks);
  const result = await getStream.array(stream, { encoding: 'utf8' });
  assert.deepStrictEqual(result, chunks, 'should collect string chunks');

  const stream2 = Readable.from(['foo', 'bar']);
  const helperResult = await collectStringChunks(stream2);
  assert.deepStrictEqual(helperResult, ['foo', 'bar'], 'helper should collect string chunks');
}

async function testBufferStream() {
  const buf1 = Buffer.from('chunk1');
  const buf2 = Buffer.from('chunk2');
  const stream = Readable.from([buf1, buf2]);
  const result = await getStream.array(stream, { encoding: 'buffer' });
  assert.strictEqual(result.length, 2);
  assert.ok(Buffer.isBuffer(result[0]));
  assert.ok(Buffer.isBuffer(result[1]));
  assert.deepStrictEqual(result[0], buf1);
  assert.deepStrictEqual(result[1], buf2);

  const stream2 = Readable.from([Buffer.from('helper')]);
  const helperResult = await collectBufferChunks(stream2);
  assert.strictEqual(helperResult.length, 1);
  assert.ok(Buffer.isBuffer(helperResult[0]));
  assert.deepStrictEqual(helperResult[0], Buffer.from('helper'));
}

async function testEmptyStream() {
  const stream = Readable.from([]);
  const result = await getStream.array(stream);
  assert.deepStrictEqual(result, [], 'should resolve to empty array for empty stream');
}

async function testMaxBufferExceeded() {
  // Test maxBuffer exceeded in object mode (chunk count limit)
  const itemStream = Readable.from(['item1', 'item2', 'item3']);
  await assert.rejects(
    async () => {
      await getStream.array(itemStream, { maxBuffer: 2 });
    },
    (err) => {
      assert.ok(err instanceof MaxBufferError || err.name === 'MaxBufferError', 'should be MaxBufferError');
      assert.strictEqual(err.message, 'maxBuffer exceeded');
      return true;
    }
  );

  // Test maxBuffer exceeded with string encoding (byte/char length limit)
  const stringStream = Readable.from(['exceeding length']);
  await assert.rejects(
    async () => {
      await getStream.array(stringStream, { encoding: 'utf8', maxBuffer: 5 });
    },
    (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 failure');
  const stream = new Readable({
    read() {
      this.destroy(customError);
    }
  });

  await assert.rejects(
    async () => {
      await getStream.array(stream);
    },
    (err) => {
      assert.strictEqual(err, customError);
      return true;
    }
  );
}

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

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

async function runAll() {
  await testObjectModeStream();
  await testStringStream();
  await testBufferStream();
  await testEmptyStream();
  await testMaxBufferExceeded();
  await testStreamError();
  await testMissingStream();
  console.log('All get-stream.array contract tests passed successfully.');
}

await runAll();

オリジンシーダー

匿名