CodeSampleX

샘플

bare-buffer 3.7.0: Buffer.prototype.writeInt16BE

검증된 샘플 — npm bare-buffer 3.7.0: Buffer.prototype.writeInt16BE. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: writeInt16BE writes positive…

sha256:a2a51ac3980a2c9043f3b591da4d88986ee3dc0b7255f8036ff1d90272a96b3b

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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.writeInt16BE in pkg:npm/bare-buffer@3.7.0
패키지
심벌
  • Buffer.prototype.writeInt16BE
환경
node 22.23.2
생성일
2026-08-27T05:44:26Z

컨트랙트

  1. writeInt16BE writes positive 16-bit signed integer in big-endian byte order at specified offset
  2. writeInt16BE writes negative 16-bit signed integer as two's complement in big-endian byte order
  3. writeInt16BE returns the offset plus number of bytes written
  4. writeInt16BE throws RangeError when offset is out of buffer bounds
  5. writeInt16BE throws RangeError when offset is negative

파일

  • PROMPT.md
  • csx.json
  • index.js
  • 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 Buffer.prototype.writeInt16BE 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.writeInt16BE
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.
csx.json
{"case":{"caseId":"case:sha256:fe79bf551e2e7a88e2485d5ca52250516157e490cd9ea2f8703ac085cc0c9454","constraints":{"executionContext":"node"},"contract":["writeInt16BE writes positive 16-bit signed integer in big-endian byte order at specified offset","writeInt16BE writes negative 16-bit signed integer as two's complement in big-endian byte order","writeInt16BE returns the offset plus number of bytes written","writeInt16BE throws RangeError when offset is out of buffer bounds","writeInt16BE throws RangeError when offset is negative"],"goal":"verify Buffer.prototype.writeInt16BE in pkg:npm/bare-buffer@3.7.0","kind":"HOW","packages":["pkg:npm/bare-buffer@3.7.0"],"schemaVersion":1,"symbols":["Buffer.prototype.writeInt16BE"]},"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.writeInt16BE"],"verifierAdapter":"node-typescript@1"}
index.js
import Module from 'node:module';

const mockBinding = {
  constants: {
    MAX_LENGTH: 2147483647,
    MAX_STRING_LENGTH: 1073741799
  },
  alloc(len) {
    return new ArrayBuffer(len);
  },
  allocUnsafe(len) {
    return new ArrayBuffer(len);
  }
};

const origCompile = Module.prototype._compile;
Module.prototype._compile = function (content, filename) {
  if (filename.includes('bare-buffer/binding.js')) {
    this.exports = mockBinding;
    this.loaded = true;
    return;
  }
  return origCompile.call(this, content, filename);
};

const { default: Buffer } = await import('bare-buffer');

export function writeInt16BE(buffer, value, offset = 0) {
  return buffer.writeInt16BE(value, offset);
}

export function createBuffer(size) {
  return Buffer.alloc(size);
}

export default Buffer;
package-lock.json
{
  "name": "sample-bare-buffer-write-int16be",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-bare-buffer-write-int16be",
      "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"
      }
    }
  }
}
package.json
{
  "name": "sample-bare-buffer-write-int16be",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "bare-buffer": "3.7.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify Buffer.prototype.writeInt16BE in pkg:npm/bare-buffer@3.7.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/bare-buffer@3.7.0"
  ],
  "symbols": [
    "Buffer.prototype.writeInt16BE"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "esm",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import Buffer, { writeInt16BE, createBuffer } from '../index.js';

// 1. writeInt16BE writes positive 16-bit signed integer in big-endian byte order at specified offset
const buf1 = createBuffer(4);
const ret1 = writeInt16BE(buf1, 0x1234, 0);
assert.strictEqual(buf1[0], 0x12, 'First byte must be high byte 0x12');
assert.strictEqual(buf1[1], 0x34, 'Second byte must be low byte 0x34');
assert.strictEqual(buf1.readInt16BE(0), 0x1234, 'readInt16BE must return written 0x1234');

// 2. writeInt16BE writes negative 16-bit signed integer as two's complement in big-endian byte order
const buf2 = createBuffer(4);
const ret2 = writeInt16BE(buf2, -1234, 2);
assert.strictEqual(buf2[2], 0xfb, 'Third byte must be high byte 0xfb');
assert.strictEqual(buf2[3], 0x2e, 'Fourth byte must be low byte 0x2e');
assert.strictEqual(buf2.readInt16BE(2), -1234, 'readInt16BE must return written -1234');

// 3. writeInt16BE returns the offset plus number of bytes written
assert.strictEqual(ret1, 2, 'writeInt16BE at offset 0 must return offset + 2 = 2');
assert.strictEqual(ret2, 4, 'writeInt16BE at offset 2 must return offset + 2 = 4');

// 4. writeInt16BE throws RangeError when offset is out of buffer bounds
assert.throws(() => {
  const smallBuf = createBuffer(2);
  writeInt16BE(smallBuf, 0x1234, 2);
}, RangeError, 'writeInt16BE must throw RangeError when offset exceeds buffer capacity');

// 5. writeInt16BE throws RangeError when offset is negative
assert.throws(() => {
  const smallBuf = createBuffer(4);
  writeInt16BE(smallBuf, 0x1234, -1);
}, RangeError, 'writeInt16BE must throw RangeError when offset is negative');

console.log('Contract verification finished successfully.');

오리진 시더

익명