示例
pngjs 6.0.0: PNG.sync.write
已验证示例 — npm pngjs 6.0.0: PNG.sync.write. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: assert PNG.sync.write synchronously encodes a PNG instance to…
sha256:2a9fbf0340e9afbe710152e08a6ac7ca20b825292cecd18899a950118726be01
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 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 debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-09-01 |
案例
HOW- 目标
- verify PNG.sync.write in pkg:npm/pngjs@6.0.0
- 符号
-
- PNG.sync.write
- 环境
- node 22.23.2
- 创建时间
- 2026-09-01T10:59:02Z
契约
- assert PNG.sync.write synchronously encodes a PNG instance to a binary Buffer with standard PNG magic header
- assert PNG.sync.write produces valid PNG data that preserves pixel RGBA values when read back with PNG.sync.read
- assert PNG.sync.write supports compression and filter options such as deflateLevel and filterType
- assert PNG.sync.write correctly encodes single-pixel 1x1 images
文件
- 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 PNG.sync.write in pkg:npm/pngjs@6.0.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/pngjs@6.0.0
Demonstrate these symbols/APIs:
- PNG.sync.write
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:cb66cd45df16befaf441cc1d42c334c3f4f42d2f4a948317d27d2d55eba7920e","contract":["assert PNG.sync.write synchronously encodes a PNG instance to a binary Buffer with standard PNG magic header","assert PNG.sync.write produces valid PNG data that preserves pixel RGBA values when read back with PNG.sync.read","assert PNG.sync.write supports compression and filter options such as deflateLevel and filterType","assert PNG.sync.write correctly encodes single-pixel 1x1 images"],"goal":"verify PNG.sync.write in pkg:npm/pngjs@6.0.0","kind":"HOW","packages":["pkg:npm/pngjs@6.0.0"],"schemaVersion":1,"symbols":["PNG.sync.write"]},"contractCommand":["node","test/contract.mjs"],"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/pngjs@6.0.0"],"schemaVersion":1,"subject":"pkg:npm/pngjs@6.0.0","symbols":["PNG.sync.write"],"verifierAdapter":"node-typescript@1"}
const { PNG } = require('pngjs');
/**
* Creates and synchronously encodes a PNG image with RGBA pixel data.
*
* @param {number} width - Image width in pixels
* @param {number} height - Image height in pixels
* @param {Buffer|Uint8Array} [rgbaData] - Raw RGBA pixel data
* @param {Object} [options] - Options passed to PNG.sync.write
* @returns {Buffer} Encoded PNG binary buffer
*/
function encodePngSync(width, height, rgbaData, options) {
const png = new PNG({ width, height });
if (rgbaData) {
if (rgbaData.length !== width * height * 4) {
throw new Error(`Invalid RGBA buffer length: expected ${width * height * 4}, got ${rgbaData.length}`);
}
rgbaData.copy(png.data);
}
return PNG.sync.write(png, options);
}
module.exports = {
encodePngSync,
PNG,
};
{
"name": "sample-pngjs-sync-write",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-pngjs-sync-write",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"pngjs": "6.0.0"
}
},
"node_modules/pngjs": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/pngjs/-/pngjs-6.0.0.tgz",
"integrity": "sha512-TRzzuFRRmEoSW/p1KVAmiOgPco2Irlah+bGFCeNfJXxxYGwSw7YwAOAcd7X28K/m5bjBWKsC29KyoMfHbypayg==",
"license": "MIT",
"engines": {
"node": ">=12.13.0"
}
}
}
}
{
"name": "sample-pngjs-sync-write",
"version": "1.0.0",
"description": "Clean-room sample verifying PNG.sync.write in pkg:npm/pngjs@6.0.0",
"main": "index.js",
"license": "MIT-0",
"dependencies": {
"pngjs": "6.0.0"
}
}
{
"schemaVersion": 1,
"goal": "verify PNG.sync.write in pkg:npm/pngjs@6.0.0",
"kind": "HOW",
"packages": [
"pkg:npm/pngjs@6.0.0"
],
"symbols": [
"PNG.sync.write"
]
}
import assert from 'node:assert';
import { PNG } from 'pngjs';
import { encodePngSync } from '../index.js';
// 1. assert PNG.sync.write synchronously encodes a PNG instance to a binary Buffer with standard PNG magic header
const png1 = new PNG({ width: 2, height: 2 });
png1.data[0] = 255; png1.data[1] = 0; png1.data[2] = 0; png1.data[3] = 255; // Red
png1.data[4] = 0; png1.data[5] = 255; png1.data[6] = 0; png1.data[7] = 255; // Green
png1.data[8] = 0; png1.data[9] = 0; png1.data[10] = 255; png1.data[11] = 255; // Blue
png1.data[12] = 255; png1.data[13] = 255; png1.data[14] = 0; png1.data[15] = 255; // Yellow
const outBuffer = PNG.sync.write(png1);
assert(Buffer.isBuffer(outBuffer), 'PNG.sync.write must return a Buffer instance');
assert(outBuffer.length > 8, 'PNG buffer must contain PNG header');
const pngSignature = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
assert.deepStrictEqual(
Array.from(outBuffer.subarray(0, 8)),
pngSignature,
'PNG.sync.write output must start with the standard PNG 8-byte header'
);
// 2. assert PNG.sync.write produces valid PNG data that preserves pixel RGBA values when read back with PNG.sync.read
const decoded = PNG.sync.read(outBuffer);
assert.strictEqual(decoded.width, 2, 'Decoded PNG width must match original');
assert.strictEqual(decoded.height, 2, 'Decoded PNG height must match original');
assert.deepStrictEqual(
Array.from(decoded.data),
Array.from(png1.data),
'Decoded pixel RGBA data must exactly match original image data'
);
// 3. assert PNG.sync.write supports compression and filter options such as deflateLevel and filterType
const png3 = new PNG({ width: 4, height: 4 });
for (let i = 0; i < png3.data.length; i += 4) {
png3.data[i] = (i * 17) % 256;
png3.data[i + 1] = (i * 31) % 256;
png3.data[i + 2] = (i * 47) % 256;
png3.data[i + 3] = 255;
}
const compressedBuf = PNG.sync.write(png3, {
deflateLevel: 9,
filterType: 4,
});
assert(Buffer.isBuffer(compressedBuf), 'PNG.sync.write with options must return a Buffer');
const decodedCompressed = PNG.sync.read(compressedBuf);
assert.strictEqual(decodedCompressed.width, 4);
assert.strictEqual(decodedCompressed.height, 4);
assert.deepStrictEqual(
Array.from(decodedCompressed.data),
Array.from(png3.data),
'Decoded pixel data with custom compression options must match original'
);
// 4. assert PNG.sync.write correctly encodes single-pixel 1x1 images
const png1x1 = new PNG({ width: 1, height: 1 });
png1x1.data[0] = 128;
png1x1.data[1] = 64;
png1x1.data[2] = 32;
png1x1.data[3] = 200;
const buf1x1 = PNG.sync.write(png1x1);
const decoded1x1 = PNG.sync.read(buf1x1);
assert.strictEqual(decoded1x1.width, 1);
assert.strictEqual(decoded1x1.height, 1);
assert.strictEqual(decoded1x1.data[0], 128);
assert.strictEqual(decoded1x1.data[1], 64);
assert.strictEqual(decoded1x1.data[2], 32);
assert.strictEqual(decoded1x1.data[3], 200);
console.log('All contract assertions passed.');
原始种子者
匿名