Exemple
string_decoder 1.3.0: StringDecoder
Échantillon vérifié pour npm string_decoder 1.3.0: StringDecoder. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.
sha256:623c6142bb0da0a0b73e4ec0c0db0895db0790ea592d8a6a49f11cc45d0d8750
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 1
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| 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 |
Cas
HOW- Objectif
- verify string_decoder.StringDecoder in pkg:npm/string_decoder@1.3.0
- Paquets
- Symboles
-
- string_decoder.StringDecoder
- Environnement
- node 22.23.2
- Créé
- 2026-08-23T08:07:15Z
Contrat
- StringDecoder instantiates and decodes complete UTF-8 buffers
- StringDecoder buffers incomplete multi-byte UTF-8 sequences across chunk boundaries
- StringDecoder end with buffer parameter decodes trailing buffer and flushes in a single call
- StringDecoder end flushes incomplete trailing multi-byte sequences as unicode replacement character
- StringDecoder supports base64, hex, and latin1 encodings
- decodeChunks streams and decodes multi-part buffer arrays preserving character boundaries
Fichiers
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.js
Code source
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 string_decoder.StringDecoder in pkg:npm/string_decoder@1.3.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/string_decoder@1.3.0
Demonstrate these symbols/APIs:
- string_decoder.StringDecoder
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- 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:711fa9ea160f6c473f0ec31c91348105df4368941621cd1b8201dfee7617da3f","constraints":{"executionContext":"node"},"contract":["StringDecoder instantiates and decodes complete UTF-8 buffers","StringDecoder buffers incomplete multi-byte UTF-8 sequences across chunk boundaries","StringDecoder end with buffer parameter decodes trailing buffer and flushes in a single call","StringDecoder end flushes incomplete trailing multi-byte sequences as unicode replacement character","StringDecoder supports base64, hex, and latin1 encodings","decodeChunks streams and decodes multi-part buffer arrays preserving character boundaries"],"goal":"verify string_decoder.StringDecoder in pkg:npm/string_decoder@1.3.0","kind":"HOW","packages":["pkg:npm/string_decoder@1.3.0"],"schemaVersion":1,"symbols":["string_decoder.StringDecoder"]},"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","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/string_decoder@1.3.0"],"schemaVersion":1,"subject":"pkg:npm/string_decoder@1.3.0","symbols":["string_decoder.StringDecoder"],"verifierAdapter":"node-typescript@1"}
const { StringDecoder } = require('string_decoder');
/**
* Decodes an array of Buffer chunks into a string using StringDecoder.
* Handles multi-byte characters split across chunk boundaries.
*
* @param {Buffer[]} chunks
* @param {string} [encoding='utf8']
* @returns {string}
*/
function decodeChunks(chunks, encoding = 'utf8') {
const decoder = new StringDecoder(encoding);
let result = '';
for (const chunk of chunks) {
result += decoder.write(chunk);
}
result += decoder.end();
return result;
}
/**
* Creates a configured StringDecoder instance.
*
* @param {string} [encoding='utf8']
* @returns {StringDecoder}
*/
function createDecoder(encoding = 'utf8') {
return new StringDecoder(encoding);
}
module.exports = {
StringDecoder,
decodeChunks,
createDecoder,
};
{
"name": "sample-string-decoder",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-string-decoder",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"string_decoder": "1.3.0"
}
},
"node_modules/safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"license": "MIT"
},
"node_modules/string_decoder": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
"integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==",
"license": "MIT",
"dependencies": {
"safe-buffer": "~5.2.0"
}
}
}
}
{
"name": "sample-string-decoder",
"version": "1.0.0",
"description": "Verify string_decoder.StringDecoder in pkg:npm/string_decoder@1.3.0",
"main": "index.js",
"scripts": {
"test": "node test/contract.js"
},
"dependencies": {
"string_decoder": "1.3.0"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify string_decoder.StringDecoder in pkg:npm/string_decoder@1.3.0",
"kind": "HOW",
"packages": [
"pkg:npm/string_decoder@1.3.0"
],
"symbols": [
"string_decoder.StringDecoder"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
const assert = require('node:assert');
const { StringDecoder, decodeChunks, createDecoder } = require('../index.js');
// 1. Instantiation and basic decoding
{
const decoder = createDecoder('utf8');
assert(decoder instanceof StringDecoder);
const result = decoder.write(Buffer.from('Hello, CodeSampleX!'));
assert.strictEqual(result, 'Hello, CodeSampleX!');
assert.strictEqual(decoder.end(), '');
}
// 2. Decode multi-byte UTF-8 sequence split across chunks (2-byte character: 'é' -> 0xc3 0xa9)
{
const decoder = new StringDecoder('utf8');
assert.strictEqual(decoder.write(Buffer.from([0xc3])), '');
assert.strictEqual(decoder.write(Buffer.from([0xa9])), 'é');
assert.strictEqual(decoder.end(), '');
}
// 3. Decode multi-byte UTF-8 sequence split across chunks (3-byte character: '한' -> 0xed 0x95 0x9c)
{
const decoder = new StringDecoder('utf8');
assert.strictEqual(decoder.write(Buffer.from([0xed, 0x95])), '');
assert.strictEqual(decoder.write(Buffer.from([0x9c])), '한');
assert.strictEqual(decoder.end(), '');
}
// 4. Decode 4-byte UTF-8 emoji split across multiple chunks ('🚀' -> 0xf0 0x9f 0x9a 0x80)
{
const decoder = new StringDecoder('utf8');
assert.strictEqual(decoder.write(Buffer.from([0xf0])), '');
assert.strictEqual(decoder.write(Buffer.from([0x9f, 0x9a])), '');
assert.strictEqual(decoder.write(Buffer.from([0x80])), '🚀');
assert.strictEqual(decoder.end(), '');
}
// 5. end(buffer) decodes the trailing buffer and flushes
{
const decoder = new StringDecoder('utf8');
assert.strictEqual(decoder.write(Buffer.from([0xf0, 0x9f])), '');
const endResult = decoder.end(Buffer.from([0x9a, 0x80]));
assert.strictEqual(endResult, '🚀');
}
// 6. Incomplete trailing multi-byte sequence flushes replacement character on end()
{
const decoder = new StringDecoder('utf8');
assert.strictEqual(decoder.write(Buffer.from([0xed, 0x95])), '');
assert.strictEqual(decoder.end(), '\ufffd');
}
// 7. Supports different encodings: base64, hex, latin1
{
const b64Decoder = new StringDecoder('base64');
assert.strictEqual(b64Decoder.write(Buffer.from('Hello ')), 'SGVsbG8g');
assert.strictEqual(b64Decoder.end(Buffer.from('world')), 'd29ybGQ=');
const hexDecoder = new StringDecoder('hex');
assert.strictEqual(hexDecoder.write(Buffer.from([0xab, 0xcd])), 'abcd');
assert.strictEqual(hexDecoder.end(Buffer.from([0xef])), 'ef');
const latin1Decoder = new StringDecoder('latin1');
assert.strictEqual(latin1Decoder.write(Buffer.from([0xe9, 0xf1])), 'éñ');
assert.strictEqual(latin1Decoder.end(), '');
}
// 8. decodeChunks helper function streams chunks correctly
{
const chunks = [
Buffer.from([0xed, 0x95]),
Buffer.from([0x9c, 0x20]),
Buffer.from([0xf0, 0x9f]),
Buffer.from([0x9a, 0x80]),
];
assert.strictEqual(decodeChunks(chunks, 'utf8'), '한 🚀');
}
console.log('All StringDecoder contract assertions passed.');
Seeder d'origine
anonyme