CodeSampleX

示例

minipass 3.3.6

已验证示例 — npm minipass 3.3.6. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: Minipass synchronous write and read operations handle string and buffer…

sha256:1cd7f581e922c8f8edbc48a8c3cdb58235ec0e708d022927aa295e2cb01c7694

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 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 alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-21

案例

HOW
目标
verify pkg:npm/minipass@3.3.6
包
环境
node 22.23.2
创建时间
2026-08-21T18:06:21Z

契约

  1. Minipass synchronous write and read operations handle string and buffer chunks with encoding conversion
  2. Minipass pipe forwards data between stream instances with automatic flow control and event forwarding
  3. Minipass objectMode preserves JavaScript objects without buffer coercion or serialization
  4. Minipass collect and concat asynchronously accumulate streamed chunks into arrays and strings
  5. Minipass promise resolves on stream completion and rejects on stream destruction with error
  6. Minipass pause and resume manage flowing state and buffer drained chunks

文件

  • 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: verify pkg:npm/minipass@3.3.6
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/minipass@3.3.6
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:384e28a77b381f7eab09644fb7897f0d36adf8f75cd425ecae12f8390e555567","constraints":{"executionContext":"node"},"contract":["Minipass synchronous write and read operations handle string and buffer chunks with encoding conversion","Minipass pipe forwards data between stream instances with automatic flow control and event forwarding","Minipass objectMode preserves JavaScript objects without buffer coercion or serialization","Minipass collect and concat asynchronously accumulate streamed chunks into arrays and strings","Minipass promise resolves on stream completion and rejects on stream destruction with error","Minipass pause and resume manage flowing state and buffer drained chunks"],"goal":"verify pkg:npm/minipass@3.3.6","kind":"HOW","packages":["pkg:npm/minipass@3.3.6"],"schemaVersion":1},"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/minipass@3.3.6"],"schemaVersion":1,"subject":"pkg:npm/minipass@3.3.6","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-minipass",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-minipass",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "minipass": "3.3.6"
      }
    },
    "node_modules/minipass": {
      "version": "3.3.6",
      "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz",
      "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==",
      "license": "ISC",
      "dependencies": {
        "yallist": "^4.0.0"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/yallist": {
      "version": "4.0.0",
      "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
      "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
      "license": "ISC"
    }
  }
}
package.json
{
  "name": "sample-minipass",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for minipass",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "minipass": "3.3.6"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/minipass@3.3.6",
  "kind": "HOW",
  "packages": [
    "pkg:npm/minipass@3.3.6"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const Minipass = require('minipass');

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

/**
 * Pipes data from source stream to destination stream.
 * @param {Minipass} src
 * @param {Minipass} dest
 * @returns {Minipass}
 */
function pipeStream(src, dest) {
  return src.pipe(dest);
}

/**
 * Collects all chunks from a stream into an array.
 * @param {Minipass} stream
 * @returns {Promise<Array>}
 */
async function collectStream(stream) {
  return stream.collect();
}

/**
 * Concatenates all chunks from a stream into a single string or Buffer.
 * @param {Minipass} stream
 * @returns {Promise<string|Buffer>}
 */
async function concatStream(stream) {
  return stream.concat();
}

module.exports = {
  Minipass,
  createStream,
  pipeStream,
  collectStream,
  concatStream
};
test/contract.js
const assert = require('node:assert/strict');
const {
  Minipass,
  createStream,
  pipeStream,
  collectStream,
  concatStream
} = require('../src/index.js');

async function main() {
  // 1. Minipass synchronous write and read operations handle string and buffer chunks with encoding conversion
  {
    const stream = createStream({ encoding: 'utf8' });
    assert.equal(stream.encoding, 'utf8');
    assert.equal(stream.bufferLength, 0);

    stream.write(Buffer.from('hello '));
    stream.write('world');
    assert.equal(stream.bufferLength, 11);

    const chunk = stream.read();
    assert.equal(chunk, 'hello world');
    assert.equal(stream.bufferLength, 0);

    stream.end();
    assert.equal(stream.emittedEnd, true);
  }

  // 2. Minipass pipe forwards data between stream instances with automatic flow control and event forwarding
  {
    const src = createStream();
    const dest = createStream();
    pipeStream(src, dest);

    const received = [];
    dest.on('data', (chunk) => {
      received.push(chunk.toString());
    });

    src.write('pipeline-');
    src.write('data');
    src.end();

    assert.equal(dest.emittedEnd, true);
    assert.equal(received.join(''), 'pipeline-data');
  }

  // 3. Minipass objectMode preserves JavaScript objects without buffer coercion or serialization
  {
    const stream = createStream({ objectMode: true });
    assert.equal(stream.objectMode, true);

    const payload1 = { id: 101, type: 'event' };
    const payload2 = { id: 102, type: 'metric' };

    stream.write(payload1);
    stream.write(payload2);
    stream.end();

    const items = [];
    for (const item of stream) {
      items.push(item);
    }
    assert.deepEqual(items, [payload1, payload2]);
  }

  // 4. Minipass collect and concat asynchronously accumulate streamed chunks into arrays and strings
  {
    const stream1 = createStream({ encoding: 'utf8' });
    stream1.write('chunk-1');
    stream1.write('chunk-2');
    stream1.end();
    const collected = await collectStream(stream1);
    assert.equal(collected.length, 2);
    assert.equal(collected[0], 'chunk-1');
    assert.equal(collected[1], 'chunk-2');
    assert.equal(collected.dataLength, 14);

    const stream2 = createStream({ encoding: 'utf8' });
    stream2.write('partA');
    stream2.write('partB');
    stream2.end();
    const concatenated = await concatStream(stream2);
    assert.equal(concatenated, 'partApartB');
  }

  // 5. Minipass promise resolves on stream completion and rejects on stream destruction with error
  {
    const stream1 = createStream();
    const p1 = stream1.promise();
    stream1.write('data');
    stream1.end();
    await p1;

    const stream2 = createStream();
    const p2 = stream2.promise();
    const failureErr = new Error('simulated failure');
    stream2.destroy(failureErr);
    await assert.rejects(p2, { message: 'simulated failure' });
  }

  // 6. Minipass pause and resume manage flowing state and buffer drained chunks
  {
    const stream = createStream({ encoding: 'utf8' });
    stream.pause();
    assert.equal(stream.paused, true);

    const chunks = [];
    stream.on('data', (chunk) => {
      chunks.push(chunk);
    });

    stream.write('delayed-content');
    assert.equal(chunks.length, 0);
    assert.equal(stream.bufferLength, 15);

    stream.resume();
    assert.equal(stream.paused, false);
    assert.equal(chunks.length, 1);
    assert.equal(chunks[0], 'delayed-content');
    assert.equal(stream.bufferLength, 0);

    stream.end();
  }

  console.log('Contract assertions passed.');
}

main().catch((err) => {
  console.error(err);
  process.exit(1);
});

原始种子者

匿名