CodeSampleX

示例

read-binary-file-arch 1.0.6: readBinaryFileArch

已验证示例 — npm read-binary-file-arch 1.0.6: readBinaryFileArch. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: readBinaryFileArch detects x64…

sha256:73ed359a17b0e4fdb833fb4988a4788a73e3e75677c9130b438b468640979599

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 linux 24 · ubuntu · glibc 2.39 x64 npm

验证运行环境

环境 契约 阶段 运行日期
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-06

案例

HOW
目标
verify read-binary-file-arch.readBinaryFileArch in pkg:npm/read-binary-file-arch@1.0.6
包
符号
  • read-binary-file-arch.readBinaryFileArch
创建时间
2026-09-06T09:43:15Z

契约

  1. readBinaryFileArch detects x64 architecture for Node.js executable binary
  2. readBinaryFileArch identifies x64 architecture from synthetic PE binary header
  3. readBinaryFileArch identifies ia32 architecture from synthetic PE binary header
  4. readBinaryFileArch returns null for non-binary plain text files
  5. readBinaryFileArch rejects directory paths with an error indicating target is not a file
  6. readBinaryFileArch rejects non-existent file paths with ENOENT error

文件

  • PROMPT.md
  • csx.json
  • index.mjs
  • package-lock.json
  • package.json
  • spec.json
  • 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 read-binary-file-arch.readBinaryFileArch in pkg:npm/read-binary-file-arch@1.0.6
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/read-binary-file-arch@1.0.6
Demonstrate these symbols/APIs:
  - read-binary-file-arch.readBinaryFileArch

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:9f49fa3325d0ead5083d7fd0df57de16d5e83552e549b7200aede06900869929","contract":["readBinaryFileArch detects x64 architecture for Node.js executable binary","readBinaryFileArch identifies x64 architecture from synthetic PE binary header","readBinaryFileArch identifies ia32 architecture from synthetic PE binary header","readBinaryFileArch returns null for non-binary plain text files","readBinaryFileArch rejects directory paths with an error indicating target is not a file","readBinaryFileArch rejects non-existent file paths with ENOENT error"],"goal":"verify read-binary-file-arch.readBinaryFileArch in pkg:npm/read-binary-file-arch@1.0.6","kind":"HOW","packages":["pkg:npm/read-binary-file-arch@1.0.6"],"schemaVersion":1,"symbols":["read-binary-file-arch.readBinaryFileArch"]},"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/read-binary-file-arch@1.0.6"],"schemaVersion":1,"subject":"pkg:npm/read-binary-file-arch@1.0.6","symbols":["read-binary-file-arch.readBinaryFileArch"],"verifierAdapter":"node-typescript@1"}
index.mjs
import { readBinaryFileArch } from 'read-binary-file-arch';

export { readBinaryFileArch };

export async function detectBinaryArch(filePath) {
  return readBinaryFileArch(filePath);
}
package-lock.json
{
  "name": "sample-read-binary-file-arch",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-read-binary-file-arch",
      "version": "1.0.0",
      "dependencies": {
        "read-binary-file-arch": "1.0.6"
      }
    },
    "node_modules/debug": {
      "version": "4.4.3",
      "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
      "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
      "license": "MIT",
      "dependencies": {
        "ms": "^2.1.3"
      },
      "engines": {
        "node": ">=6.0"
      },
      "peerDependenciesMeta": {
        "supports-color": {
          "optional": true
        }
      }
    },
    "node_modules/ms": {
      "version": "2.1.3",
      "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
      "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
      "license": "MIT"
    },
    "node_modules/read-binary-file-arch": {
      "version": "1.0.6",
      "resolved": "https://registry.npmjs.org/read-binary-file-arch/-/read-binary-file-arch-1.0.6.tgz",
      "integrity": "sha512-BNg9EN3DD3GsDXX7Aa8O4p92sryjkmzYYgmgTAc6CA4uGLEDzFfxOxugu21akOxpcXHiEgsYkC6nPsQvLLLmEg==",
      "license": "MIT",
      "dependencies": {
        "debug": "^4.3.4"
      },
      "bin": {
        "read-binary-file-arch": "cli.js"
      }
    }
  }
}
package.json
{
  "name": "sample-read-binary-file-arch",
  "version": "1.0.0",
  "type": "module",
  "main": "index.mjs",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "read-binary-file-arch": "1.0.6"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify read-binary-file-arch.readBinaryFileArch in pkg:npm/read-binary-file-arch@1.0.6",
  "kind": "HOW",
  "packages": [
    "pkg:npm/read-binary-file-arch@1.0.6"
  ],
  "symbols": [
    "read-binary-file-arch.readBinaryFileArch"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import os from 'node:os';
import { readBinaryFileArch } from 'read-binary-file-arch';
import { detectBinaryArch } from '../index.mjs';

const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'csx-contract-'));

try {
  function createSyntheticPE(machineType) {
    const buf = Buffer.alloc(1024);
    buf.write('MZ', 0, 'ascii');
    buf.writeUInt32LE(0x80, 0x3c);
    buf.write('PE\0\0', 0x80, 'ascii');
    buf.writeUInt16LE(machineType, 0x84);
    return buf;
  }

  // 1. readBinaryFileArch detects x64 architecture for Node.js executable binary
  {
    const arch = await readBinaryFileArch(process.execPath);
    assert.equal(arch, 'x64');
    const helperArch = await detectBinaryArch(process.execPath);
    assert.equal(helperArch, 'x64');
  }

  // 2. readBinaryFileArch identifies x64 architecture from synthetic PE binary header
  {
    const pePath = path.join(tempDir, 'dummy_x64.exe');
    fs.writeFileSync(pePath, createSyntheticPE(0x8664));
    const arch = await readBinaryFileArch(pePath);
    assert.equal(arch, 'x64');
    const helperArch = await detectBinaryArch(pePath);
    assert.equal(helperArch, 'x64');
  }

  // 3. readBinaryFileArch identifies ia32 architecture from synthetic PE binary header
  {
    const pePath = path.join(tempDir, 'dummy_ia32.exe');
    fs.writeFileSync(pePath, createSyntheticPE(0x014c));
    const arch = await readBinaryFileArch(pePath);
    assert.equal(arch, 'ia32');
    const helperArch = await detectBinaryArch(pePath);
    assert.equal(helperArch, 'ia32');
  }

  // 4. readBinaryFileArch returns null for non-binary plain text files
  {
    const textPath = path.join(tempDir, 'sample.txt');
    fs.writeFileSync(textPath, 'This is a plain text file without binary headers.');
    const arch = await readBinaryFileArch(textPath);
    assert.equal(arch, null);
    const helperArch = await detectBinaryArch(textPath);
    assert.equal(helperArch, null);
  }

  // 5. readBinaryFileArch rejects directory paths with an error indicating target is not a file
  {
    await assert.rejects(
      async () => {
        await readBinaryFileArch(tempDir);
      },
      {
        name: 'Error',
        message: `${tempDir} is not a file.`,
      }
    );
  }

  // 6. readBinaryFileArch rejects non-existent file paths with ENOENT error
  {
    const missingPath = path.join(tempDir, 'missing_file.bin');
    await assert.rejects(
      async () => {
        await readBinaryFileArch(missingPath);
      },
      (err) => {
        assert.equal(err.code, 'ENOENT');
        return true;
      }
    );
  }

  console.log('All readBinaryFileArch contract assertions passed.');
} finally {
  fs.rmSync(tempDir, { recursive: true, force: true });
}

原始种子者

匿名