CodeSampleX

Ejemplo

iconv-lite 0.4.24: getDecoder

Muestra verificada para npm iconv-lite 0.4.24: getDecoder. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó.

sha256:fe511f784ced4ab597500ffd165b6ed93e83bba4d6c659e7dae04a3400b77fd2

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-20

Caso

HOW
Objetivo
verify iconv-lite.getDecoder in pkg:npm/iconv-lite@0.4.24
Paquetes
Símbolos
  • iconv-lite.getDecoder
Entorno
node 22.23.2
Creado
2026-08-20T19:15:26Z

Contrato

  1. assert iconv.getDecoder returns stateful decoder for chunked utf-8 streams across byte boundaries
  2. assert iconv.getDecoder decodes multibyte cjk streams in euc-kr and shift_jis across chunk splits
  3. assert iconv.getDecoder decodes single-byte windows-1251 and windows-1252 byte sequences
  4. assert iconv.getDecoder respects stripBOM option for byte order mark handling
  5. assert iconv.getDecoder flushes incomplete trailing multibyte sequences upon calling end

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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 iconv-lite.getDecoder in pkg:npm/iconv-lite@0.4.24
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/iconv-lite@0.4.24
Demonstrate these symbols/APIs:
  - iconv-lite.getDecoder
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - 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:a7da66d2f92da4739ddbbc944abb2b35f2b69a1891ca0ad1d6d33db3dea4af87","constraints":{"executionContext":"node"},"contract":["assert iconv.getDecoder returns stateful decoder for chunked utf-8 streams across byte boundaries","assert iconv.getDecoder decodes multibyte cjk streams in euc-kr and shift_jis across chunk splits","assert iconv.getDecoder decodes single-byte windows-1251 and windows-1252 byte sequences","assert iconv.getDecoder respects stripBOM option for byte order mark handling","assert iconv.getDecoder flushes incomplete trailing multibyte sequences upon calling end"],"goal":"verify iconv-lite.getDecoder in pkg:npm/iconv-lite@0.4.24","kind":"HOW","packages":["pkg:npm/iconv-lite@0.4.24"],"schemaVersion":1,"symbols":["iconv-lite.getDecoder"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/iconv-lite@0.4.24"],"schemaVersion":1,"subject":"pkg:npm/iconv-lite@0.4.24","symbols":["iconv-lite.getDecoder"],"verifierAdapter":"node-typescript@1"}
index.js
const iconv = require('iconv-lite');

function createDecoder(encoding, options) {
  return iconv.getDecoder(encoding, options);
}

function decodeChunks(encoding, chunks, options) {
  const decoder = iconv.getDecoder(encoding, options);
  let result = '';
  for (const chunk of chunks) {
    const text = decoder.write(chunk);
    if (text) {
      result += text;
    }
  }
  const trailing = decoder.end();
  if (trailing) {
    result += trailing;
  }
  return result;
}

module.exports = {
  createDecoder,
  decodeChunks,
};
package-lock.json
{
  "name": "sample-iconv-lite-get-decoder",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-iconv-lite-get-decoder",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "iconv-lite": "0.4.24"
      }
    },
    "node_modules/iconv-lite": {
      "version": "0.4.24",
      "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
      "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
      "license": "MIT",
      "dependencies": {
        "safer-buffer": ">= 2.1.2 < 3"
      },
      "engines": {
        "node": ">=0.10.0"
      }
    },
    "node_modules/safer-buffer": {
      "version": "2.1.2",
      "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
      "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-iconv-lite-get-decoder",
  "version": "1.0.0",
  "description": "Demonstrate iconv-lite.getDecoder streaming decoder usage",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "license": "MIT-0",
  "dependencies": {
    "iconv-lite": "0.4.24"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify iconv-lite.getDecoder in pkg:npm/iconv-lite@0.4.24",
  "kind": "HOW",
  "packages": [
    "pkg:npm/iconv-lite@0.4.24"
  ],
  "symbols": [
    "iconv-lite.getDecoder"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "runtime": "node@22.23.2"
  }
}
test/contract.js
const assert = require('assert');
const { createDecoder, decodeChunks } = require('../index');

function runTests() {
  // 1. Stateful UTF-8 chunk decoding across byte boundaries
  const decUtf8 = createDecoder('utf-8');
  const chunk1 = decUtf8.write(Buffer.from([0xed, 0x95]));
  assert.strictEqual(chunk1, '', 'Incomplete byte sequence should yield empty string');
  const chunk2 = decUtf8.write(Buffer.from([0x9c, 0x67, 0x6c]));
  assert.strictEqual(chunk2, '한gl', 'Completed byte sequence should yield correct string');
  const endUtf8 = decUtf8.end();
  assert.strictEqual(endUtf8, '', 'Flushing clean stream should yield empty string');

  // 2. Multibyte CJK decoding: EUC-KR and Shift_JIS
  const eucChunks = [
    Buffer.from([0xc7]),
    Buffer.from([0xd1, 0xb1]),
    Buffer.from([0xdb])
  ];
  const eucResult = decodeChunks('euc-kr', eucChunks);
  assert.strictEqual(eucResult, '한글', 'EUC-KR multibyte chunk stream should decode correctly');

  const sjisChunks = [
    Buffer.from([0x93]),
    Buffer.from([0xfa, 0x96]),
    Buffer.from([0x7b, 0x8c, 0xea])
  ];
  const sjisResult = decodeChunks('shift_jis', sjisChunks);
  assert.strictEqual(sjisResult, '日本語', 'Shift_JIS multibyte chunk stream should decode correctly');

  // 3. Single-byte legacy encodings: windows-1251 and windows-1252
  const win1251Chunks = [
    Buffer.from([0xcf, 0xf0, 0xe8]),
    Buffer.from([0xe2, 0xe5, 0xf2])
  ];
  const win1251Result = decodeChunks('windows-1251', win1251Chunks);
  assert.strictEqual(win1251Result, 'Привет', 'Windows-1251 stream should decode correctly');

  const win1252Chunks = [
    Buffer.from([0x43, 0x61]),
    Buffer.from([0x66, 0xe9])
  ];
  const win1252Result = decodeChunks('windows-1252', win1252Chunks);
  assert.strictEqual(win1252Result, 'Café', 'Windows-1252 stream should decode correctly');

  // 4. Byte Order Mark (BOM) handling options
  const bomBuffer = Buffer.from([0xef, 0xbb, 0xbf, 0x68, 0x65, 0x6c, 0x6c, 0x6f]);
  const decDefault = createDecoder('utf-8');
  const defaultText = decDefault.write(bomBuffer) + (decDefault.end() || '');
  assert.strictEqual(defaultText, 'hello', 'Default decoder should strip BOM');

  const decKeepBom = createDecoder('utf-8', { stripBOM: false });
  const keepBomText = decKeepBom.write(bomBuffer) + (decKeepBom.end() || '');
  assert.strictEqual(keepBomText, '\ufeffhello', 'Decoder with stripBOM=false should retain BOM');

  // 5. Incomplete multibyte sequence at EOF flushed by end()
  const decTrailing = createDecoder('utf-8');
  const leadChunk = decTrailing.write(Buffer.from([0xed, 0x95]));
  assert.strictEqual(leadChunk, '');
  const flushed = decTrailing.end();
  assert.strictEqual(flushed, '\ufffd', 'Trailing incomplete bytes should yield replacement character on end');

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

runTests();

Seeder de origen

anónimo