CodeSampleX

サンプル

data-uri-to-buffer 6.0.2: dataUriToBuffer

検証済みサンプル — npm data-uri-to-buffer 6.0.2: dataUriToBuffer. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: dataUriToBuffer decodes plain text data…

sha256:a25afc089a6d14264fe3eb129d6b7874eede35fe5ce45f55fdacc9b91a4d13b5

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
2
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 npm

検証実行環境

環境 コントラクト ステージ 実行日
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
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-07

ケース

HOW
ゴール
verify pkg:npm/data-uri-to-buffer@6.0.2
パッケージ
シンボル
  • dataUriToBuffer
作成日
2026-08-23T15:44:23Z

コントラクト

  1. dataUriToBuffer decodes plain text data URI with default MIME type and charset
  2. dataUriToBuffer decodes base64 encoded text data URI with explicit MIME type
  3. dataUriToBuffer decodes base64 encoded JSON data URI with custom charset
  4. dataUriToBuffer accepts URL instances in addition to string URIs
  5. dataUriToBuffer decodes binary data URI with application/octet-stream MIME type
  6. dataUriToBuffer handles empty data URI returning empty buffer
  7. dataUriToBuffer parses custom MIME type parameters into typeFull and charset
  8. dataUriToBuffer throws TypeError when passed a non-data URI protocol
  9. dataUriToBuffer throws TypeError when passed a malformed data URI without comma

ファイル

  • PROMPT.md
  • csx.json
  • 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 pkg:npm/data-uri-to-buffer@6.0.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/data-uri-to-buffer@6.0.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:b6af8cd3ed1b2f44ff1ce165e5ca27056b62b136a48712ed7e6e26f8fe97505a","contract":["dataUriToBuffer decodes plain text data URI with default MIME type and charset","dataUriToBuffer decodes base64 encoded text data URI with explicit MIME type","dataUriToBuffer decodes base64 encoded JSON data URI with custom charset","dataUriToBuffer accepts URL instances in addition to string URIs","dataUriToBuffer decodes binary data URI with application/octet-stream MIME type","dataUriToBuffer handles empty data URI returning empty buffer","dataUriToBuffer parses custom MIME type parameters into typeFull and charset","dataUriToBuffer throws TypeError when passed a non-data URI protocol","dataUriToBuffer throws TypeError when passed a malformed data URI without comma"],"goal":"verify pkg:npm/data-uri-to-buffer@6.0.2","kind":"HOW","packages":["pkg:npm/data-uri-to-buffer@6.0.2"],"schemaVersion":1,"symbols":["dataUriToBuffer"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/data-uri-to-buffer@6.0.2"],"schemaVersion":1,"subject":"pkg:npm/data-uri-to-buffer@6.0.2","symbols":["dataUriToBuffer"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-data-uri-to-buffer",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-data-uri-to-buffer",
      "version": "1.0.0",
      "dependencies": {
        "data-uri-to-buffer": "6.0.2"
      }
    },
    "node_modules/data-uri-to-buffer": {
      "version": "6.0.2",
      "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-6.0.2.tgz",
      "integrity": "sha512-7hvf7/GW8e86rW0ptuwS3OcBGDjIi6SZva7hCyWC0yYry2cOPmLIjXAUHI6DK2HsnwJd9ifmt57i8eV2n4YNpw==",
      "license": "MIT",
      "engines": {
        "node": ">= 14"
      }
    }
  }
}
package.json
{
  "name": "sample-data-uri-to-buffer",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "data-uri-to-buffer": "6.0.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/data-uri-to-buffer@6.0.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/data-uri-to-buffer@6.0.2"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { dataUriToBuffer } from 'data-uri-to-buffer';

// 1. dataUriToBuffer decodes plain text data URI with default MIME type and charset
{
  const res = dataUriToBuffer('data:,Hello%2C%20World!');
  assert.equal(res.type, 'text/plain');
  assert.equal(res.typeFull, 'text/plain;charset=US-ASCII');
  assert.equal(res.charset, 'US-ASCII');
  assert.equal(new TextDecoder().decode(res.buffer), 'Hello, World!');
}

// 2. dataUriToBuffer decodes base64 encoded text data URI with explicit MIME type
{
  const res = dataUriToBuffer('data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==');
  assert.equal(res.type, 'text/plain');
  assert.equal(res.typeFull, 'text/plain');
  assert.equal(res.charset, '');
  assert.equal(new TextDecoder().decode(res.buffer), 'Hello, World!');
}

// 3. dataUriToBuffer decodes base64 encoded JSON data URI with custom charset
{
  const res = dataUriToBuffer('data:application/json;charset=utf-8;base64,eyJmb28iOiJiYXIifQ==');
  assert.equal(res.type, 'application/json');
  assert.equal(res.typeFull, 'application/json;charset=utf-8');
  assert.equal(res.charset, 'utf-8');
  assert.equal(new TextDecoder().decode(res.buffer), '{"foo":"bar"}');
}

// 4. dataUriToBuffer accepts URL instances in addition to string URIs
{
  const res = dataUriToBuffer(new URL('data:text/plain;base64,VGVzdA=='));
  assert.equal(new TextDecoder().decode(res.buffer), 'Test');
}

// 5. dataUriToBuffer decodes binary data URI with application/octet-stream MIME type
{
  const res = dataUriToBuffer('data:application/octet-stream;base64,AQIDBA==');
  assert.equal(res.type, 'application/octet-stream');
  assert.deepEqual(Array.from(new Uint8Array(res.buffer)), [1, 2, 3, 4]);
}

// 6. dataUriToBuffer handles empty data URI returning empty buffer
{
  const res = dataUriToBuffer('data:,');
  assert.equal(res.type, 'text/plain');
  assert.equal(res.typeFull, 'text/plain;charset=US-ASCII');
  assert.equal(res.charset, 'US-ASCII');
  assert.equal(res.buffer.byteLength, 0);
}

// 7. dataUriToBuffer parses custom MIME type parameters into typeFull and charset
{
  const res = dataUriToBuffer('data:text/plain;charset=UTF-8;foo=bar,test');
  assert.equal(res.type, 'text/plain');
  assert.equal(res.typeFull, 'text/plain;charset=UTF-8;foo=bar');
  assert.equal(res.charset, 'UTF-8');
  assert.equal(new TextDecoder().decode(res.buffer), 'test');
}

// 8. dataUriToBuffer throws TypeError when passed a non-data URI protocol
assert.throws(
  () => dataUriToBuffer('https://example.com'),
  {
    name: 'TypeError',
    message: '`uri` does not appear to be a Data URI (must begin with "data:")'
  }
);

// 9. dataUriToBuffer throws TypeError when passed a malformed data URI without comma
assert.throws(
  () => dataUriToBuffer('data:text/plain'),
  {
    name: 'TypeError',
    message: 'malformed data: URI'
  }
);

オリジンシーダー

匿名