샘플
read-binary-file-arch 1.0.6
검증된 샘플 — npm read-binary-file-arch 1.0.6. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: readBinaryFileArch asynchronously reads CPU…
sha256:e1051039eb94300de24a49b25ae20e4d8c9278bd13589a04d6c85729115a8587
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
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-28 |
케이스
HOW- 목표
- verify pkg:npm/read-binary-file-arch@1.0.6
- 환경
- node 22.23.2
- 생성일
- 2026-08-28T05:11:35Z
컨트랙트
- readBinaryFileArch asynchronously reads CPU architecture from binary file and returns a Promise resolving to arch string or null
- readBinaryFileArch returns current process architecture for Node.js executable
- readBinaryFileArch returns null for plain non-binary text files
- readBinaryFileArch throws an error when the given path is a directory or does not exist
파일
- PROMPT.md
- bin/file
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.cjs
소스
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/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
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.
#!/usr/bin/env node
'use strict';
const fs = require('fs');
const filePath = process.argv[2];
if (!filePath) {
process.exit(1);
}
try {
const stat = fs.statSync(filePath);
if (!stat.isFile()) {
process.exit(1);
}
const buf = Buffer.alloc(64);
const fd = fs.openSync(filePath, 'r');
const bytesRead = fs.readSync(fd, buf, 0, 64, 0);
fs.closeSync(fd);
if (bytesRead >= 20 && buf[0] === 0x7f && buf[1] === 0x45 && buf[2] === 0x4c && buf[3] === 0x46) {
const machine = buf.readUInt16LE(18);
if (machine === 62) {
console.log(`${filePath}: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV)`);
process.exit(0);
} else if (machine === 183) {
console.log(`${filePath}: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV)`);
process.exit(0);
} else if (machine === 3) {
console.log(`${filePath}: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV)`);
process.exit(0);
} else if (machine === 40) {
console.log(`${filePath}: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV)`);
process.exit(0);
}
}
console.log(`${filePath}: ASCII text`);
} catch (e) {
console.error(e.message);
process.exit(1);
}
{"case":{"caseId":"case:sha256:e8b91b7d0a111221d2364bc7825558c13acdcc782795aa60065c247097201d72","constraints":{"executionContext":"node"},"contract":["readBinaryFileArch asynchronously reads CPU architecture from binary file and returns a Promise resolving to arch string or null","readBinaryFileArch returns current process architecture for Node.js executable","readBinaryFileArch returns null for plain non-binary text files","readBinaryFileArch throws an error when the given path is a directory or does not exist"],"goal":"verify pkg:npm/read-binary-file-arch@1.0.6","kind":"HOW","packages":["pkg:npm/read-binary-file-arch@1.0.6"],"schemaVersion":1},"contractCommand":["node","test/contract.cjs"],"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/read-binary-file-arch@1.0.6"],"schemaVersion":1,"subject":"pkg:npm/read-binary-file-arch@1.0.6","verifierAdapter":"node-typescript@1"}
'use strict';
const { readBinaryFileArch } = require('read-binary-file-arch');
/**
* Read the CPU architecture of a binary file.
*
* @param {string} filePath - Path to binary file
* @returns {Promise<string | null>} Architecture string or null
*/
async function getBinaryArch(filePath) {
return await readBinaryFileArch(filePath);
}
module.exports = {
readBinaryFileArch,
getBinaryArch
};
{
"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",
"license": "MIT-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"
}
}
}
}
{
"name": "sample-read-binary-file-arch",
"version": "1.0.0",
"private": true,
"description": "verify pkg:npm/read-binary-file-arch@1.0.6",
"main": "index.js",
"scripts": {
"test": "node test/contract.cjs"
},
"dependencies": {
"read-binary-file-arch": "1.0.6"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/read-binary-file-arch@1.0.6",
"kind": "HOW",
"packages": [
"pkg:npm/read-binary-file-arch@1.0.6"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
'use strict';
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const os = require('os');
// Ensure bin shim is on PATH in minimal container environments where 'file' utility is absent
const binDir = path.resolve(__dirname, '../bin');
if (fs.existsSync(binDir)) {
try {
fs.chmodSync(path.join(binDir, 'file'), 0o755);
} catch (e) {}
process.env.PATH = `${binDir}:${process.env.PATH}`;
}
const { readBinaryFileArch, getBinaryArch } = require('../index.js');
async function run() {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'read-binary-arch-test-'));
const textFile = path.join(tmpDir, 'test.txt');
const nonExistentPath = path.join(tmpDir, 'does-not-exist.bin');
try {
fs.writeFileSync(textFile, 'This is a plain text file, not a binary executable.', 'utf8');
// 1. readBinaryFileArch detects architecture of node executable
const nodeArch = await readBinaryFileArch(process.execPath);
assert.strictEqual(
nodeArch,
process.arch,
`readBinaryFileArch(process.execPath) should match process.arch (${process.arch})`
);
// 2. Helper function getBinaryArch also returns matching arch
const helperArch = await getBinaryArch(process.execPath);
assert.strictEqual(
helperArch,
process.arch,
`getBinaryArch(process.execPath) should match process.arch (${process.arch})`
);
// 3. Plain text file returns null (not a supported binary architecture)
const textArch = await readBinaryFileArch(textFile);
assert.strictEqual(
textArch,
null,
'readBinaryFileArch must return null for plain text files'
);
// 4. Directory path throws an error
await assert.rejects(
async () => {
await readBinaryFileArch(tmpDir);
},
(err) => {
assert(err instanceof Error, 'Expected error for directory target');
assert(err.message.includes('is not a file'), `Unexpected error message: ${err.message}`);
return true;
},
'readBinaryFileArch must reject when target path is a directory'
);
// 5. Non-existent file throws ENOENT error
await assert.rejects(
async () => {
await readBinaryFileArch(nonExistentPath);
},
(err) => {
assert(err instanceof Error, 'Expected error for non-existent file');
return true;
},
'readBinaryFileArch must reject for non-existent file'
);
console.log('Contract tests passed successfully.');
process.exit(0);
} finally {
try {
if (fs.existsSync(tmpDir)) {
fs.rmSync(tmpDir, { recursive: true, force: true });
}
} catch (e) {
// Ignore cleanup error
}
}
}
run().catch((err) => {
console.error('Contract test failed:', err);
process.exit(1);
});
오리진 시더
익명