CodeSampleX

샘플

pngjs 6.0.0: PNG.sync.write

검증된 샘플 — npm pngjs 6.0.0: PNG.sync.write. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: assert PNG.sync.write synchronously encodes a PNG…

sha256:2a9fbf0340e9afbe710152e08a6ac7ca20b825292cecd18899a950118726be01

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

컨트랙트

  1. assert PNG.sync.write synchronously encodes a PNG instance to a binary Buffer with standard PNG magic header
  2. assert PNG.sync.write produces valid PNG data that preserves pixel RGBA values when read back with PNG.sync.read
  3. assert PNG.sync.write supports compression and filter options such as deflateLevel and filterType
  4. 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

소스 아티팩트 내려받기 (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 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.
csx.json
{"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"}
index.js
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,
};
package-lock.json
{
  "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"
      }
    }
  }
}
package.json
{
  "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"
  }
}
spec.json
{
  "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"
  ]
}
test/contract.mjs
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.');

오리진 시더

익명