CodeSampleX

サンプル

isbinaryfile 4.0.10

検証済みサンプル — npm isbinaryfile 4.0.10. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: isBinaryFileSync returns false for plain text buffer and true…

sha256:b102ec45b8d12e0911dc695f9bea236dabe2a2f67f18b9a625e7d0da97468ad1

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。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@1
2026-08-21

ケース

HOW
ゴール
verify pkg:npm/isbinaryfile@4.0.10
パッケージ
作成日
2026-08-21T14:32:43Z

コントラクト

  1. isBinaryFileSync returns false for plain text buffer and true for binary buffer
  2. isBinaryFile asynchronously returns false for plain text buffer and true for binary buffer
  3. isBinaryFile and isBinaryFileSync correctly detect binary status for file paths

ファイル

  • 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/isbinaryfile@4.0.10
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/isbinaryfile@4.0.10

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:f639cf6bf102a4c6b826285062a52f85b5a587f0cf9ae8b395a5d0ebb14730ef","contract":["isBinaryFileSync returns false for plain text buffer and true for binary buffer","isBinaryFile asynchronously returns false for plain text buffer and true for binary buffer","isBinaryFile and isBinaryFileSync correctly detect binary status for file paths"],"goal":"verify pkg:npm/isbinaryfile@4.0.10","kind":"HOW","packages":["pkg:npm/isbinaryfile@4.0.10"],"schemaVersion":1},"contractCommand":["node","test/contract.js"],"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/isbinaryfile@4.0.10"],"schemaVersion":1,"subject":"pkg:npm/isbinaryfile@4.0.10","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-isbinaryfile",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-isbinaryfile",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "isbinaryfile": "4.0.10"
      }
    },
    "node_modules/isbinaryfile": {
      "version": "4.0.10",
      "resolved": "https://registry.npmjs.org/isbinaryfile/-/isbinaryfile-4.0.10.tgz",
      "integrity": "sha512-iHrqe5shvBUcFbmZq9zOQHBoeOhZJu6RQGrDpBgenUm/Am+F3JM2MgQj+rK3Z601fzrL5gLZWtAPH2OBaSVcyw==",
      "license": "MIT",
      "engines": {
        "node": ">= 8.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-isbinaryfile",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for isbinaryfile",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "isbinaryfile": "4.0.10"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/isbinaryfile@4.0.10",
  "kind": "HOW",
  "packages": [
    "pkg:npm/isbinaryfile@4.0.10"
  ]
}
src/index.js
const { isBinaryFile, isBinaryFileSync } = require('isbinaryfile');

async function detectBinary(file, size) {
  return await isBinaryFile(file, size);
}

function detectBinarySync(file, size) {
  return isBinaryFileSync(file, size);
}

module.exports = {
  detectBinary,
  detectBinarySync
};
test/contract.js
const assert = require('node:assert');
const fs = require('node:fs');
const path = require('node:path');
const os = require('node:os');
const { isBinaryFile, isBinaryFileSync } = require('isbinaryfile');
const { detectBinary, detectBinarySync } = require('../src/index.js');

async function runTests() {
  // 1. Buffer detection (synchronous)
  const textBuffer = Buffer.from('Hello world! This is plain text ASCII content.\nLine two.\n');
  const binaryBuffer = Buffer.from([0x00, 0xFF, 0x00, 0x7F, 0x80, 0xFE, 0x01, 0x02, 0x03]);

  assert.strictEqual(isBinaryFileSync(textBuffer, textBuffer.length), false, 'text buffer should not be binary');
  assert.strictEqual(detectBinarySync(textBuffer, textBuffer.length), false, 'helper text buffer sync should return false');

  assert.strictEqual(isBinaryFileSync(binaryBuffer, binaryBuffer.length), true, 'binary buffer should be binary');
  assert.strictEqual(detectBinarySync(binaryBuffer, binaryBuffer.length), true, 'helper binary buffer sync should return true');

  // 2. Buffer detection (asynchronous)
  const textAsync = await isBinaryFile(textBuffer, textBuffer.length);
  assert.strictEqual(textAsync, false, 'async text buffer should return false');
  const textHelperAsync = await detectBinary(textBuffer, textBuffer.length);
  assert.strictEqual(textHelperAsync, false, 'helper async text buffer should return false');

  const binaryAsync = await isBinaryFile(binaryBuffer, binaryBuffer.length);
  assert.strictEqual(binaryAsync, true, 'async binary buffer should return true');
  const binaryHelperAsync = await detectBinary(binaryBuffer, binaryBuffer.length);
  assert.strictEqual(binaryHelperAsync, true, 'helper async binary buffer should return true');

  // 3. File path detection (synchronous and asynchronous)
  const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'isbin-contract-'));
  const textFilePath = path.join(tmpDir, 'sample-text.txt');
  const binaryFilePath = path.join(tmpDir, 'sample-binary.bin');

  try {
    fs.writeFileSync(textFilePath, 'Plain text content for file test.\nSecond line.\n');
    fs.writeFileSync(binaryFilePath, Buffer.from([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00]));

    // Sync file path
    assert.strictEqual(isBinaryFileSync(textFilePath), false, 'sync text file should return false');
    assert.strictEqual(detectBinarySync(textFilePath), false, 'helper sync text file should return false');
    assert.strictEqual(isBinaryFileSync(binaryFilePath), true, 'sync binary file should return true');
    assert.strictEqual(detectBinarySync(binaryFilePath), true, 'helper sync binary file should return true');

    // Async file path
    assert.strictEqual(await isBinaryFile(textFilePath), false, 'async text file should return false');
    assert.strictEqual(await detectBinary(textFilePath), false, 'helper async text file should return false');
    assert.strictEqual(await isBinaryFile(binaryFilePath), true, 'async binary file should return true');
    assert.strictEqual(await detectBinary(binaryFilePath), true, 'helper async binary file should return true');
  } finally {
    fs.rmSync(tmpDir, { recursive: true, force: true });
  }

  console.log('Contract tests passed successfully.');
}

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

オリジンシーダー

匿名