サンプル
graceful-fs 4.2.11: readFileSync
検証済みサンプル — npm graceful-fs 4.2.11: readFileSync. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: graceful-fs.readFileSync(path, 'utf8') reads…
sha256:06af6fec3859f0d3813c9934ffa53bc26e6a123c12c18607b2367c40f57f696c
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
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-05 |
ケース
HOW- ゴール
- verify graceful-fs.readFileSync in pkg:npm/graceful-fs@4.2.11
- パッケージ
- シンボル
-
- graceful-fs.readFileSync
- 作成日
- 2026-09-05T19:04:52Z
コントラクト
- graceful-fs.readFileSync(path, 'utf8') reads file content synchronously and returns a UTF-8 string
- graceful-fs.readFileSync(path) without encoding options returns a Buffer containing raw file bytes
- graceful-fs.readFileSync(path, { encoding: 'base64' }) returns file content as a base64 encoded string
- graceful-fs.readFileSync(fd) reads file content synchronously from an open file descriptor
- graceful-fs.readFileSync(nonExistentPath) throws an ENOENT error when target file does not exist
ファイル
- PROMPT.md
- csx.json
- index.mjs
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
- test/fixture.txt
ソース
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 graceful-fs.readFileSync in pkg:npm/graceful-fs@4.2.11
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/graceful-fs@4.2.11
Demonstrate these symbols/APIs:
- graceful-fs.readFileSync
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.
{"case":{"caseId":"case:sha256:bea664fc689f0298b82d8684beed7f2e31b5ec8082d3db6da849343ea7171dea","contract":["graceful-fs.readFileSync(path, 'utf8') reads file content synchronously and returns a UTF-8 string","graceful-fs.readFileSync(path) without encoding options returns a Buffer containing raw file bytes","graceful-fs.readFileSync(path, { encoding: 'base64' }) returns file content as a base64 encoded string","graceful-fs.readFileSync(fd) reads file content synchronously from an open file descriptor","graceful-fs.readFileSync(nonExistentPath) throws an ENOENT error when target file does not exist"],"goal":"verify graceful-fs.readFileSync in pkg:npm/graceful-fs@4.2.11","kind":"HOW","packages":["pkg:npm/graceful-fs@4.2.11"],"schemaVersion":1,"symbols":["graceful-fs.readFileSync"]},"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/graceful-fs@4.2.11"],"schemaVersion":1,"subject":"pkg:npm/graceful-fs@4.2.11","symbols":["graceful-fs.readFileSync"],"verifierAdapter":"node-typescript@1"}
import gracefulFs from 'graceful-fs';
/**
* Reads the entire contents of a file synchronously as a UTF-8 string.
*
* @param {string|Buffer|URL|number} pathOrFd - Path to file or file descriptor.
* @returns {string} File contents decoded as UTF-8 string.
*/
export function readTextFile(pathOrFd) {
return gracefulFs.readFileSync(pathOrFd, 'utf8');
}
/**
* Reads the entire contents of a file synchronously as a raw Buffer.
*
* @param {string|Buffer|URL|number} pathOrFd - Path to file or file descriptor.
* @returns {Buffer} File contents as raw byte Buffer.
*/
export function readBinaryFile(pathOrFd) {
return gracefulFs.readFileSync(pathOrFd);
}
/**
* Reads the contents of a file synchronously with custom options or encoding.
*
* @param {string|Buffer|URL|number} pathOrFd - Path to file or file descriptor.
* @param {string|Object} options - Encoding string or options object.
* @returns {string|Buffer} File contents.
*/
export function readFileWithOptions(pathOrFd, options) {
return gracefulFs.readFileSync(pathOrFd, options);
}
export default gracefulFs;
{
"name": "sample-graceful-fs-readfilesync",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-graceful-fs-readfilesync",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"graceful-fs": "4.2.11"
}
},
"node_modules/graceful-fs": {
"version": "4.2.11",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
"license": "ISC"
}
}
}
{
"name": "sample-graceful-fs-readfilesync",
"version": "1.0.0",
"type": "module",
"private": true,
"license": "MIT-0",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"graceful-fs": "4.2.11"
}
}
{
"schemaVersion": 1,
"goal": "verify graceful-fs.readFileSync in pkg:npm/graceful-fs@4.2.11",
"kind": "HOW",
"packages": [
"pkg:npm/graceful-fs@4.2.11"
],
"symbols": [
"graceful-fs.readFileSync"
]
}
import assert from 'node:assert/strict';
import { fileURLToPath } from 'node:url';
import path from 'node:path';
import gracefulFs from 'graceful-fs';
import { readTextFile, readBinaryFile, readFileWithOptions } from '../index.mjs';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const fixturePath = path.join(__dirname, 'fixture.txt');
const expectedContent = 'Hello CodeSampleX graceful-fs verification!\nLine 2 for multi-line test.\n';
const expectedBuffer = Buffer.from(expectedContent, 'utf8');
// 1. Verify graceful-fs.readFileSync(path, 'utf8') reads file content synchronously and returns a UTF-8 string
const strDirect = gracefulFs.readFileSync(fixturePath, 'utf8');
assert.equal(typeof strDirect, 'string');
assert.equal(strDirect, expectedContent);
const strHelper = readTextFile(fixturePath);
assert.equal(strHelper, expectedContent);
// 2. Verify graceful-fs.readFileSync(path) without encoding options returns a Buffer containing raw file bytes
const bufDirect = gracefulFs.readFileSync(fixturePath);
assert.ok(Buffer.isBuffer(bufDirect));
assert.ok(bufDirect.equals(expectedBuffer));
const bufHelper = readBinaryFile(fixturePath);
assert.ok(Buffer.isBuffer(bufHelper));
assert.ok(bufHelper.equals(expectedBuffer));
// 3. Verify graceful-fs.readFileSync(path, { encoding: 'base64' }) returns file content as a base64 encoded string
const b64Direct = gracefulFs.readFileSync(fixturePath, { encoding: 'base64' });
assert.equal(typeof b64Direct, 'string');
assert.equal(b64Direct, expectedBuffer.toString('base64'));
const b64Helper = readFileWithOptions(fixturePath, { encoding: 'base64' });
assert.equal(b64Helper, expectedBuffer.toString('base64'));
// 4. Verify graceful-fs.readFileSync(fd) reads file content synchronously from an open file descriptor
const fd1 = gracefulFs.openSync(fixturePath, 'r');
try {
const fdBuf = gracefulFs.readFileSync(fd1);
assert.ok(Buffer.isBuffer(fdBuf));
assert.ok(fdBuf.equals(expectedBuffer));
} finally {
gracefulFs.closeSync(fd1);
}
const fd2 = gracefulFs.openSync(fixturePath, 'r');
try {
const fdStr = readTextFile(fd2);
assert.equal(typeof fdStr, 'string');
assert.equal(fdStr, expectedContent);
} finally {
gracefulFs.closeSync(fd2);
}
// 5. Verify graceful-fs.readFileSync(nonExistentPath) throws an ENOENT error when target file does not exist
const nonExistentPath = path.join(__dirname, 'non_existent_fixture_12345.txt');
assert.throws(
() => gracefulFs.readFileSync(nonExistentPath),
(err) => {
assert.equal(err.code, 'ENOENT');
return true;
}
);
assert.throws(
() => readTextFile(nonExistentPath),
(err) => {
assert.equal(err.code, 'ENOENT');
return true;
}
);
console.log('Contract assertions passed successfully.');
Hello CodeSampleX graceful-fs verification!
Line 2 for multi-line test.
オリジンシーダー
匿名