CodeSampleX

샘플

string_decoder 1.1.1

검증된 샘플 — npm string_decoder 1.1.1. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: StringDecoder() instantiates with default utf8 encoding and…

sha256:6af13ac4f1feade6da94ab07c259511bd3c911b9c8db07fa268970fb70208e72

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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-23

케이스

HOW
목표
verify pkg:npm/string_decoder@1.1.1
패키지
환경
node 22.23.2
생성일
2026-08-23T07:31:31Z

컨트랙트

  1. StringDecoder() instantiates with default utf8 encoding and supports custom encodings like latin1, base64, and hex
  2. StringDecoder.prototype.write() buffers incomplete multi-byte UTF-8 sequences across chunk boundaries
  3. StringDecoder.prototype.write() decodes multi-byte UTF-8 sequences including 4-byte emojis when completed
  4. StringDecoder.prototype.write() returns complete ASCII and UTF-8 strings immediately
  5. StringDecoder.prototype.end() flushes trailing incomplete bytes as Unicode replacement characters
  6. StringDecoder.prototype.end(buffer) decodes the final buffer chunk and flushes the decoder
  7. StringDecoder.prototype.write() and end() decode base64 across buffer boundaries
  8. StringDecoder.prototype.write() and end() decode hex across buffer boundaries

파일

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.cjs

소스 아티팩트 내려받기 (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/string_decoder@1.1.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/string_decoder@1.1.1

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:771db1497064592311d05c8d8eedc877d824a84633a8a41d156031431407978a","contract":["StringDecoder() instantiates with default utf8 encoding and supports custom encodings like latin1, base64, and hex","StringDecoder.prototype.write() buffers incomplete multi-byte UTF-8 sequences across chunk boundaries","StringDecoder.prototype.write() decodes multi-byte UTF-8 sequences including 4-byte emojis when completed","StringDecoder.prototype.write() returns complete ASCII and UTF-8 strings immediately","StringDecoder.prototype.end() flushes trailing incomplete bytes as Unicode replacement characters","StringDecoder.prototype.end(buffer) decodes the final buffer chunk and flushes the decoder","StringDecoder.prototype.write() and end() decode base64 across buffer boundaries","StringDecoder.prototype.write() and end() decode hex across buffer boundaries"],"goal":"verify pkg:npm/string_decoder@1.1.1","kind":"HOW","packages":["pkg:npm/string_decoder@1.1.1"],"schemaVersion":1,"symbols":["StringDecoder","StringDecoder.prototype.write","StringDecoder.prototype.end"]},"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/string_decoder@1.1.1"],"schemaVersion":1,"subject":"pkg:npm/string_decoder@1.1.1","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-string-decoder",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-string-decoder",
      "version": "1.0.0",
      "dependencies": {
        "string_decoder": "1.1.1"
      }
    },
    "node_modules/safe-buffer": {
      "version": "5.1.2",
      "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
      "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
      "license": "MIT"
    },
    "node_modules/string_decoder": {
      "version": "1.1.1",
      "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
      "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
      "license": "MIT",
      "dependencies": {
        "safe-buffer": "~5.1.0"
      }
    }
  }
}
package.json
{
  "name": "sample-string-decoder",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for string_decoder",
  "main": "src/index.js",
  "dependencies": {
    "string_decoder": "1.1.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/string_decoder@1.1.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/string_decoder@1.1.1"
  ]
}
src/index.js
const { StringDecoder } = require('string_decoder');

/**
 * Creates a new StringDecoder instance with the specified encoding.
 * @param {string} [encoding='utf8'] - The character encoding to use.
 * @returns {StringDecoder} A new StringDecoder instance.
 */
function createDecoder(encoding) {
  return new StringDecoder(encoding);
}

/**
 * Decodes a buffer or array of buffers sequentially using StringDecoder.
 * @param {Buffer[]} chunks - Array of Buffer chunks to decode.
 * @param {string} [encoding='utf8'] - Character encoding.
 * @returns {string} Fully decoded string.
 */
function decodeChunks(chunks, encoding) {
  const decoder = new StringDecoder(encoding);
  let result = '';
  for (let i = 0; i < chunks.length; i++) {
    result += decoder.write(chunks[i]);
  }
  result += decoder.end();
  return result;
}

module.exports = {
  StringDecoder,
  createDecoder,
  decodeChunks
};
test/contract.cjs
const assert = require('node:assert');
const { StringDecoder } = require('string_decoder');
const { createDecoder, decodeChunks } = require('../src/index.js');

// 1. StringDecoder() instantiates with default utf8 encoding and supports custom encodings like latin1, base64, and hex
const utf8Decoder = new StringDecoder();
assert.strictEqual(utf8Decoder.encoding, 'utf8');

const helperUtf8 = createDecoder();
assert.strictEqual(helperUtf8.encoding, 'utf8');

const latin1Decoder = new StringDecoder('latin1');
assert.strictEqual(latin1Decoder.encoding, 'latin1');

const base64Decoder = new StringDecoder('base64');
assert.strictEqual(base64Decoder.encoding, 'base64');

const hexDecoder = new StringDecoder('hex');
assert.strictEqual(hexDecoder.encoding, 'hex');

// 2. StringDecoder.prototype.write() buffers incomplete multi-byte UTF-8 sequences across chunk boundaries
const euroDecoder = new StringDecoder('utf8');
const euroPart1 = Buffer.from([0xE2, 0x82]);
const euroPart2 = Buffer.from([0xAC]);
assert.strictEqual(euroDecoder.write(euroPart1), '');
assert.strictEqual(euroDecoder.write(euroPart2), '€');

// 3. StringDecoder.prototype.write() decodes multi-byte UTF-8 sequences including 4-byte emojis when completed
const emojiDecoder = new StringDecoder('utf8');
const emPart1 = Buffer.from([0xF0, 0x9F]);
const emPart2 = Buffer.from([0x9A, 0x80]); // 🚀 (\uD83D\uDE80)
assert.strictEqual(emojiDecoder.write(emPart1), '');
assert.strictEqual(emojiDecoder.write(emPart2), '🚀');

// Helper function decodeChunks test
const decodedEmoji = decodeChunks([emPart1, emPart2], 'utf8');
assert.strictEqual(decodedEmoji, '🚀');

// 4. StringDecoder.prototype.write() returns complete ASCII and UTF-8 strings immediately
const greetingDecoder = new StringDecoder('utf8');
assert.strictEqual(greetingDecoder.write(Buffer.from('Hello, ')), 'Hello, ');
assert.strictEqual(greetingDecoder.write(Buffer.from('World!')), 'World!');

// 5. StringDecoder.prototype.end() flushes trailing incomplete bytes as Unicode replacement characters
const incompleteDecoder = new StringDecoder('utf8');
assert.strictEqual(incompleteDecoder.write(Buffer.from([0xE2, 0x82])), '');
assert.strictEqual(incompleteDecoder.end(), '\uFFFD');

// 6. StringDecoder.prototype.end(buffer) decodes the final buffer chunk and flushes the decoder
const endWithBufDecoder = new StringDecoder('utf8');
assert.strictEqual(endWithBufDecoder.end(Buffer.from('Final chunk')), 'Final chunk');

// 7. StringDecoder.prototype.write() and end() decode base64 across buffer boundaries
const b64Dec = new StringDecoder('base64');
const b64Buf1 = Buffer.from('Hello ');
const b64Buf2 = Buffer.from('World');
const out1 = b64Dec.write(b64Buf1);
const out2 = b64Dec.end(b64Buf2);
assert.strictEqual(out1 + out2, Buffer.from('Hello World').toString('base64'));

// 8. StringDecoder.prototype.write() and end() decode hex across buffer boundaries
const hexDec = new StringDecoder('hex');
const hexBuf1 = Buffer.from([0xde, 0xad]);
const hexBuf2 = Buffer.from([0xbe, 0xef]);
assert.strictEqual(hexDec.write(hexBuf1), 'dead');
assert.strictEqual(hexDec.end(hexBuf2), 'beef');

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

오리진 시더

익명