CodeSampleX

示例

get-uri 6.0.5: getUri

已验证示例 — npm get-uri 6.0.5: getUri. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: getUri reads plain text data URIs into a Readable stream returning…

sha256:221d111be17c053333ac877b50c4831c60f85885cd0f02c3e206aea9c440e447

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
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-27

案例

HOW
目标
verify get-uri.getUri in pkg:npm/get-uri@6.0.5
包
符号
  • get-uri.getUri
创建时间
2026-08-27T11:40:32Z

契约

  1. getUri reads plain text data URIs into a Readable stream returning decoded payload
  2. getUri accepts URL object instances for data URIs
  3. getUri decodes base64-encoded data URIs into a Readable stream returning binary payload
  4. getUri reads local file URIs into a Readable stream returning file content
  5. getUri throws ENOTMODIFIED error when passed a cached stream for an unchanged file URI
  6. getUri throws ENOTMODIFIED error when passed a cached stream for an unchanged data URI
  7. getUri throws TypeError when passed an empty URI
  8. getUri throws TypeError when passed an unsupported protocol URI
  9. getUri throws ENOTFOUND error when file URI target does not exist

文件

  • 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 get-uri.getUri in pkg:npm/get-uri@6.0.5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/get-uri@6.0.5
Demonstrate these symbols/APIs:
  - get-uri.getUri

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:2ac62ab483e36b34195fe0506b6159996963e9f8587c8ebd4240fa1dcf5f51d5","contract":["getUri reads plain text data URIs into a Readable stream returning decoded payload","getUri accepts URL object instances for data URIs","getUri decodes base64-encoded data URIs into a Readable stream returning binary payload","getUri reads local file URIs into a Readable stream returning file content","getUri throws ENOTMODIFIED error when passed a cached stream for an unchanged file URI","getUri throws ENOTMODIFIED error when passed a cached stream for an unchanged data URI","getUri throws TypeError when passed an empty URI","getUri throws TypeError when passed an unsupported protocol URI","getUri throws ENOTFOUND error when file URI target does not exist"],"goal":"verify get-uri.getUri in pkg:npm/get-uri@6.0.5","kind":"HOW","packages":["pkg:npm/get-uri@6.0.5"],"schemaVersion":1,"symbols":["get-uri.getUri"]},"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/get-uri@6.0.5"],"schemaVersion":1,"subject":"pkg:npm/get-uri@6.0.5","symbols":["get-uri.getUri"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-get-uri",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-get-uri",
      "version": "1.0.0",
      "dependencies": {
        "get-uri": "6.0.5"
      }
    },
    "node_modules/basic-ftp": {
      "version": "5.3.1",
      "resolved": "https://registry.npmjs.org/basic-ftp/-/basic-ftp-5.3.1.tgz",
      "integrity": "sha512-bopVNp6ugyA150DDuZfPFdt1KZ5a94ZDiwX4hMgZDzF+GttD80lEy8kj98kbyhLXnPvhtIo93mdnLIjpCAeeOw==",
      "license": "MIT",
      "engines": {
        "node": ">=10.0.0"
      }
    },
    "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"
      }
    },
    "node_modules/debug": {
      "version": "4.4.3",
      "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
      "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
      "license": "MIT",
      "dependencies": {
        "ms": "^2.1.3"
      },
      "engines": {
        "node": ">=6.0"
      },
      "peerDependenciesMeta": {
        "supports-color": {
          "optional": true
        }
      }
    },
    "node_modules/get-uri": {
      "version": "6.0.5",
      "resolved": "https://registry.npmjs.org/get-uri/-/get-uri-6.0.5.tgz",
      "integrity": "sha512-b1O07XYq8eRuVzBNgJLstU6FYc1tS6wnMtF1I1D9lE8LxZSOGZ7LhxN54yPP6mGw5f2CkXY2BQUL9Fx41qvcIg==",
      "license": "MIT",
      "dependencies": {
        "basic-ftp": "^5.0.2",
        "data-uri-to-buffer": "^6.0.2",
        "debug": "^4.3.4"
      },
      "engines": {
        "node": ">= 14"
      }
    },
    "node_modules/ms": {
      "version": "2.1.3",
      "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
      "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-get-uri",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "get-uri": "6.0.5"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify get-uri.getUri in pkg:npm/get-uri@6.0.5",
  "kind": "HOW",
  "packages": [
    "pkg:npm/get-uri@6.0.5"
  ],
  "symbols": [
    "get-uri.getUri"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { promises as fs } from 'node:fs';
import path from 'node:path';
import { pathToFileURL } from 'node:url';
import { getUri } from 'get-uri';

async function streamToBuffer(stream) {
  const chunks = [];
  for await (const chunk of stream) {
    chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk);
  }
  return Buffer.concat(chunks);
}

// 1. getUri reads plain text data URIs into a Readable stream
const dataUri = 'data:text/plain;charset=utf-8,Hello%20World';
const dataStream = await getUri(dataUri);
const dataPayload = await streamToBuffer(dataStream);
assert.equal(dataPayload.toString('utf8'), 'Hello World');

// 2. getUri accepts URL object instances for data URIs
const urlObj = new URL('data:text/plain;charset=utf-8,From%20URL%20Object');
const urlStream = await getUri(urlObj);
const urlPayload = await streamToBuffer(urlStream);
assert.equal(urlPayload.toString('utf8'), 'From URL Object');

// 3. getUri decodes base64-encoded data URIs
const base64Uri = 'data:text/plain;base64,SGVsbG8gQ29kZVNhbXBsZVg=';
const base64Stream = await getUri(base64Uri);
const base64Payload = await streamToBuffer(base64Stream);
assert.equal(base64Payload.toString('utf8'), 'Hello CodeSampleX');

// 4. getUri reads local file URIs into a Readable stream
const tempFilePath = path.resolve('test-contract-temp.txt');
await fs.writeFile(tempFilePath, 'contract test file content', 'utf8');

try {
  const fileUri = pathToFileURL(tempFilePath).href;
  const fileStream = await getUri(fileUri);
  const filePayload = await streamToBuffer(fileStream);
  assert.equal(filePayload.toString('utf8'), 'contract test file content');

  // 5. getUri throws ENOTMODIFIED error when passed a cached stream for unchanged file URI
  await assert.rejects(
    async () => {
      await getUri(fileUri, { cache: fileStream });
    },
    (err) => {
      assert.equal(err.code, 'ENOTMODIFIED');
      return true;
    }
  );
} finally {
  await fs.unlink(tempFilePath).catch(() => {});
}

// 6. getUri throws ENOTMODIFIED error when passed a cached stream for unchanged data URI
await assert.rejects(
  async () => {
    await getUri(dataUri, { cache: dataStream });
  },
  (err) => {
    assert.equal(err.code, 'ENOTMODIFIED');
    return true;
  }
);

// 7. getUri throws TypeError when passed an empty URI
await assert.rejects(
  async () => {
    await getUri('');
  },
  {
    name: 'TypeError',
    message: 'Must pass in a URI to "getUri()"'
  }
);

// 8. getUri throws TypeError when passed an unsupported protocol URI
await assert.rejects(
  async () => {
    await getUri('customproto://localhost/sample');
  },
  {
    name: 'TypeError',
    message: 'Unsupported protocol "customproto" specified in URI: "customproto://localhost/sample"'
  }
);

// 9. getUri throws ENOTFOUND error when file URI target does not exist
const nonExistentUri = pathToFileURL(path.resolve('non-existent-contract-target.txt')).href;
await assert.rejects(
  async () => {
    await getUri(nonExistentUri);
  },
  (err) => {
    assert.equal(err.code, 'ENOTFOUND');
    return true;
  }
);

原始种子者

匿名