示例
bare-buffer 3.7.0: Buffer.prototype.readFloatBE
已验证示例 — npm bare-buffer 3.7.0: Buffer.prototype.readFloatBE. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: readFloatBE reads 32-bit big-endian…
sha256:535e5657bad590483df07e03d7bfa51eccd604b865d9354cc2a7c2589084dc70
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 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@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-08-27 |
案例
HOW- 目标
- verify Buffer.prototype.readFloatBE in pkg:npm/bare-buffer@3.7.0
- 符号
-
- Buffer.prototype.readFloatBE
- 环境
- node 22.23.2
- 创建时间
- 2026-08-27T05:35:33Z
契约
- readFloatBE reads 32-bit big-endian floating point values from default offset 0
- readFloatBE reads positive and negative floating point values accurately at specified offsets
- readFloatBE parses IEEE 754 special values including positive and negative infinity and zero
- readFloatBE correctly decodes IEEE 754 NaN values
- readFloatBE reads sequential 32-bit big-endian floats from a contiguous buffer
- readFloatBE throws RangeError when reading beyond buffer bounds or non-integer number offset
- readFloatBE throws TypeError when offset is not a number
文件
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
源代码
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 Buffer.prototype.readFloatBE in pkg:npm/bare-buffer@3.7.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/bare-buffer@3.7.0
Demonstrate these symbols/APIs:
- Buffer.prototype.readFloatBE
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: esm
- 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.
{"case":{"caseId":"case:sha256:6872acdc4bd55c2344f702bf61c58110a9911f4c00b3e3c894f7bcaeea77d140","constraints":{"executionContext":"node"},"contract":["readFloatBE reads 32-bit big-endian floating point values from default offset 0","readFloatBE reads positive and negative floating point values accurately at specified offsets","readFloatBE parses IEEE 754 special values including positive and negative infinity and zero","readFloatBE correctly decodes IEEE 754 NaN values","readFloatBE reads sequential 32-bit big-endian floats from a contiguous buffer","readFloatBE throws RangeError when reading beyond buffer bounds or non-integer number offset","readFloatBE throws TypeError when offset is not a number"],"goal":"verify Buffer.prototype.readFloatBE in pkg:npm/bare-buffer@3.7.0","kind":"HOW","packages":["pkg:npm/bare-buffer@3.7.0"],"schemaVersion":1,"symbols":["Buffer.prototype.readFloatBE"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/bare-buffer@3.7.0"],"schemaVersion":1,"subject":"pkg:npm/bare-buffer@3.7.0","symbols":["Buffer.prototype.readFloatBE"],"verifierAdapter":"node-typescript@1"}
import { createRequire } from 'node:module';
import path from 'node:path';
const require = createRequire(import.meta.url);
// Ensure binding is available in Node.js environments where require.addon is absent
if (typeof Bare === 'undefined') {
const nodeBuffer = globalThis.Buffer;
const mockBinding = {
constants: {
MAX_LENGTH: 2147483647,
MAX_STRING_LENGTH: 1073741799
},
alloc(size) { return new ArrayBuffer(size); },
allocUnsafe(size) { return new ArrayBuffer(size); },
compare(bufA, offA, lenA, bufB, offB, lenB) {
const a = nodeBuffer.from(bufA, offA, lenA);
const b = nodeBuffer.from(bufB, offB, lenB);
return a.compare(b);
},
toStringHex(buf, offset, len) {
return nodeBuffer.from(buf, offset, len).toString('hex');
},
writeHex(buf, offset, len, string) {
return nodeBuffer.from(buf, offset, len).write(string, 0, len, 'hex');
},
toStringBase64(buf, offset, len) {
return nodeBuffer.from(buf, offset, len).toString('base64');
},
writeBase64(buf, offset, len, string) {
return nodeBuffer.from(buf, offset, len).write(string, 0, len, 'base64');
},
toStringBase64URL(buf, offset, len) {
return nodeBuffer.from(buf, offset, len).toString('base64url');
},
writeBase64URL(buf, offset, len, string) {
return nodeBuffer.from(buf, offset, len).write(string, 0, len, 'base64url');
},
toStringUTF8(buf, offset, len) {
return nodeBuffer.from(buf, offset, len).toString('utf8');
},
writeUTF8(buf, offset, len, string) {
return nodeBuffer.from(buf, offset, len).write(string, 0, len, 'utf8');
},
validateUTF8(buf, offset, len) {
return nodeBuffer.isUtf8 ? nodeBuffer.isUtf8(nodeBuffer.from(buf, offset, len)) : true;
},
byteLengthUTF8(string) {
return nodeBuffer.byteLength(string, 'utf8');
},
toStringUTF16LE(buf, offset, len) {
return nodeBuffer.from(buf, offset, len).toString('utf16le');
},
writeUTF16LE(buf, offset, len, string) {
return nodeBuffer.from(buf, offset, len).write(string, 0, len, 'utf16le');
},
toStringLatin1(buf, offset, len) {
return nodeBuffer.from(buf, offset, len).toString('latin1');
},
writeLatin1(buf, offset, len, string) {
return nodeBuffer.from(buf, offset, len).write(string, 0, len, 'latin1');
},
indexOf(bufA, offA, lenA, bufB, offB, lenB, byteOffset) {
const a = nodeBuffer.from(bufA, offA, lenA);
const b = nodeBuffer.from(bufB, offB, lenB);
return a.indexOf(b, byteOffset);
},
lastIndexOf(bufA, offA, lenA, bufB, offB, lenB, byteOffset) {
const a = nodeBuffer.from(bufA, offA, lenA);
const b = nodeBuffer.from(bufB, offB, lenB);
return a.lastIndexOf(b, byteOffset);
},
swap16(buf, offset, len) {
nodeBuffer.from(buf, offset, len).swap16();
},
swap32(buf, offset, len) {
nodeBuffer.from(buf, offset, len).swap32();
},
swap64(buf, offset, len) {
nodeBuffer.from(buf, offset, len).swap64();
}
};
const mainPath = require.resolve('bare-buffer');
const bindingPath = path.join(path.dirname(mainPath), 'binding.js');
require.cache[bindingPath] = {
id: bindingPath,
filename: bindingPath,
loaded: true,
exports: mockBinding
};
}
const Buffer = require('bare-buffer');
export function readFloatBE(buffer, offset = 0) {
return buffer.readFloatBE(offset);
}
export function writeFloatBE(buffer, value, offset = 0) {
return buffer.writeFloatBE(value, offset);
}
export function readFloatBESequence(buffer, count, startOffset = 0) {
const result = new Array(count);
for (let i = 0; i < count; i++) {
result[i] = buffer.readFloatBE(startOffset + i * 4);
}
return result;
}
export function writeFloatBESequence(buffer, values, startOffset = 0) {
for (let i = 0; i < values.length; i++) {
buffer.writeFloatBE(values[i], startOffset + i * 4);
}
return startOffset + values.length * 4;
}
export default Buffer;
{
"name": "sample-bare-buffer-read-float-be",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-bare-buffer-read-float-be",
"version": "1.0.0",
"dependencies": {
"bare-buffer": "3.7.0"
}
},
"node_modules/bare-buffer": {
"version": "3.7.0",
"resolved": "https://registry.npmjs.org/bare-buffer/-/bare-buffer-3.7.0.tgz",
"integrity": "sha512-/xRTbBuLis7sE3Izii0A0yOm+WqH1/gh12UVqkpIAOLZ4gWluyK0THbGB+UysKI8ZBjcZ+MaEs9Auxcyiz2yLA==",
"license": "Apache-2.0",
"engines": {
"bare": ">=1.20.0"
}
}
}
}
{
"name": "sample-bare-buffer-read-float-be",
"version": "1.0.0",
"type": "module",
"private": true,
"dependencies": {
"bare-buffer": "3.7.0"
}
}
{
"schemaVersion": 1,
"goal": "verify Buffer.prototype.readFloatBE in pkg:npm/bare-buffer@3.7.0",
"kind": "HOW",
"packages": [
"pkg:npm/bare-buffer@3.7.0"
],
"symbols": [
"Buffer.prototype.readFloatBE"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "esm",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
import assert from 'node:assert/strict';
import Buffer, {
readFloatBE,
writeFloatBE,
readFloatBESequence,
writeFloatBESequence
} from '../index.js';
// 1. readFloatBE reads 32-bit big-endian floating point values from default offset 0
const buf1 = Buffer.alloc(4);
writeFloatBE(buf1, 1.5, 0);
assert.strictEqual(readFloatBE(buf1), 1.5, 'readFloatBE at default offset 0 should match 1.5');
assert.strictEqual(buf1.readFloatBE(0), 1.5, 'buf.readFloatBE(0) should match 1.5');
assert.strictEqual(buf1.readFloatBE(), 1.5, 'buf.readFloatBE() with default offset should match 1.5');
// 2. readFloatBE reads positive and negative floating point values accurately at specified offsets
const buf2 = Buffer.alloc(16);
writeFloatBE(buf2, 42.125, 4);
writeFloatBE(buf2, -100.5, 8);
assert.strictEqual(readFloatBE(buf2, 4), 42.125, 'readFloatBE at offset 4 should match 42.125');
assert.strictEqual(readFloatBE(buf2, 8), -100.5, 'readFloatBE at offset 8 should match -100.5');
// 3. readFloatBE parses IEEE 754 special values including positive and negative infinity and zero
const buf3 = Buffer.alloc(16);
writeFloatBE(buf3, 0.0, 0);
writeFloatBE(buf3, -0.0, 4);
writeFloatBE(buf3, Infinity, 8);
writeFloatBE(buf3, -Infinity, 12);
assert.strictEqual(readFloatBE(buf3, 0), 0, 'readFloatBE should decode +0.0');
assert.strictEqual(Object.is(readFloatBE(buf3, 4), -0), true, 'readFloatBE should decode -0.0');
assert.strictEqual(readFloatBE(buf3, 8), Infinity, 'readFloatBE should decode Infinity');
assert.strictEqual(readFloatBE(buf3, 12), -Infinity, 'readFloatBE should decode -Infinity');
// 4. readFloatBE correctly decodes IEEE 754 NaN values
const buf4 = Buffer.alloc(4);
writeFloatBE(buf4, NaN, 0);
assert.strictEqual(Number.isNaN(readFloatBE(buf4, 0)), true, 'readFloatBE should decode NaN');
// 5. readFloatBE reads sequential 32-bit big-endian floats from a contiguous buffer
const testValues = [1.0, 2.5, -3.75, 123.45600128173828];
const seqBuf = Buffer.alloc(testValues.length * 4);
writeFloatBESequence(seqBuf, testValues, 0);
const decodedValues = readFloatBESequence(seqBuf, testValues.length, 0);
for (let i = 0; i < testValues.length; i++) {
assert.strictEqual(decodedValues[i], Math.fround(testValues[i]), `Value at index ${i} should match`);
}
// 6. readFloatBE throws RangeError when reading beyond buffer bounds or non-integer number offset
const boundsBuf = Buffer.alloc(4);
assert.throws(() => readFloatBE(boundsBuf, 1), RangeError, 'offset 1 on 4-byte buffer must throw RangeError');
assert.throws(() => readFloatBE(boundsBuf, -1), RangeError, 'negative offset must throw RangeError');
assert.throws(() => readFloatBE(boundsBuf, 5), RangeError, 'offset past buffer length must throw RangeError');
assert.throws(() => readFloatBE(boundsBuf, 1.5), RangeError, 'non-integer float offset must throw RangeError');
// 7. readFloatBE throws TypeError when offset is not a number
assert.throws(() => readFloatBE(boundsBuf, null), TypeError, 'null offset must throw TypeError');
assert.throws(() => readFloatBE(boundsBuf, '0'), TypeError, 'string offset must throw TypeError');
assert.throws(() => readFloatBE(boundsBuf, false), TypeError, 'boolean offset must throw TypeError');
assert.throws(() => readFloatBE(boundsBuf, {}), TypeError, 'object offset must throw TypeError');
console.log('Buffer.prototype.readFloatBE contract tests passed successfully.');
原始种子者
匿名