CodeSampleX

Beispiel

tmp-promise 3.0.3: create and automatically cleanup temporary files and directories with tmp-promise

Verifiziertes Beispiel für npm tmp-promise 3.0.3: create and automatically cleanup temporary files and directories with tmp-promise. Der Vertrag lief auf…

sha256:8c1f7f4fdf707865562dd01b6859afe3206a4f5b734e900c8fefc442077756b0

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 npm

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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-28

Fall

HOW
Ziel
create and automatically cleanup temporary files and directories with tmp-promise
Pakete
Symbole
  • tmp-promise.dir
  • tmp-promise.file
  • tmp-promise.withDir
  • tmp-promise.withFile
Erstellt
2026-08-28T05:09:04Z

Contract

  1. file() resolves to { path, fd, cleanup } where cleanup removes the temporary file
  2. dir() resolves to { path, cleanup } where cleanup removes the temporary directory
  3. withFile(fn) provides { path, fd } to callback and automatically removes temporary file upon completion
  4. withDir(fn) provides { path } to callback and automatically removes temporary directory upon completion

Dateien

  • PROMPT.md
  • csx.json
  • index.mjs
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

Quellartefakt herunterladen (tar.gz)

Quelltext

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: create and automatically cleanup temporary files and directories with tmp-promise
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/tmp-promise@3.0.3
Demonstrate these symbols/APIs:
  - tmp-promise.dir
  - tmp-promise.file
  - tmp-promise.withDir
  - tmp-promise.withFile

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:397f7b05b7fab591308bbe9f16aafef10f6e2df4005456a54e9b265f9921b29c","contract":["file() resolves to { path, fd, cleanup } where cleanup removes the temporary file","dir() resolves to { path, cleanup } where cleanup removes the temporary directory","withFile(fn) provides { path, fd } to callback and automatically removes temporary file upon completion","withDir(fn) provides { path } to callback and automatically removes temporary directory upon completion"],"goal":"create and automatically cleanup temporary files and directories with tmp-promise","kind":"HOW","packages":["pkg:npm/tmp-promise@3.0.3"],"schemaVersion":1,"symbols":["tmp-promise.dir","tmp-promise.file","tmp-promise.withDir","tmp-promise.withFile"]},"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/tmp-promise@3.0.3"],"schemaVersion":1,"subject":"pkg:npm/tmp-promise@3.0.3","symbols":["tmp-promise.dir","tmp-promise.file","tmp-promise.withDir","tmp-promise.withFile"],"verifierAdapter":"node-typescript@1"}
index.mjs
import fs from 'node:fs/promises';
import { file, dir, withFile, withDir } from 'tmp-promise';

export async function demonstrateFileCreation() {
  const { path, fd, cleanup } = await file({ prefix: 'sample-', postfix: '.tmp' });
  try {
    await fs.writeFile(path, 'sample file content');
    return path;
  } finally {
    await cleanup();
  }
}

export async function demonstrateDirCreation() {
  const { path, cleanup } = await dir({ prefix: 'sample-dir-', unsafeCleanup: true });
  try {
    return path;
  } finally {
    await cleanup();
  }
}

export async function demonstrateWithFile() {
  return await withFile(async ({ path }) => {
    await fs.writeFile(path, 'scoped content');
    return path;
  });
}

export async function demonstrateWithDir() {
  return await withDir(async ({ path }) => {
    return path;
  }, { unsafeCleanup: true });
}
package-lock.json
{
  "name": "sample-tmp-promise",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-tmp-promise",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "tmp-promise": "3.0.3"
      }
    },
    "node_modules/tmp": {
      "version": "0.2.7",
      "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.7.tgz",
      "integrity": "sha512-e0votIpp4Uo2AJYSzVHV6xCcawuiez3DzqDAbrTc3YxBkplN6e+dM13ZeIcZnDg/QpSuU2zfZ3rzwY8ukEnaXw==",
      "license": "MIT",
      "engines": {
        "node": ">=14.14"
      }
    },
    "node_modules/tmp-promise": {
      "version": "3.0.3",
      "resolved": "https://registry.npmjs.org/tmp-promise/-/tmp-promise-3.0.3.tgz",
      "integrity": "sha512-RwM7MoPojPxsOBYnyd2hy0bxtIlVrihNs9pj5SUvY8Zz1sQcQG2tG1hSr8PDxfgEB8RNKDhqbIlroIarSNDNsQ==",
      "license": "MIT",
      "dependencies": {
        "tmp": "^0.2.0"
      }
    }
  }
}
package.json
{
  "name": "sample-tmp-promise",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "tmp-promise": "3.0.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "create and automatically cleanup temporary files and directories with tmp-promise",
  "kind": "HOW",
  "packages": [
    "pkg:npm/tmp-promise@3.0.3"
  ],
  "symbols": [
    "tmp-promise.dir",
    "tmp-promise.file",
    "tmp-promise.withDir",
    "tmp-promise.withFile"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import fs from 'node:fs';
import { file, dir, withFile, withDir } from 'tmp-promise';

async function testFile() {
  const o = await file({ prefix: 'test-file-', postfix: '.txt' });
  assert.ok(typeof o.path === 'string' && o.path.length > 0, 'file() should return path string');
  assert.ok(typeof o.fd === 'number', 'file() should return file descriptor');
  assert.ok(typeof o.cleanup === 'function', 'file() should return cleanup function');
  assert.ok(fs.existsSync(o.path), 'temporary file should exist on disk');

  fs.writeSync(o.fd, Buffer.from('hello tmp file'));
  await o.cleanup();
  assert.strictEqual(fs.existsSync(o.path), false, 'cleanup() should remove temporary file');
}

async function testDir() {
  const o = await dir({ prefix: 'test-dir-', unsafeCleanup: true });
  assert.ok(typeof o.path === 'string' && o.path.length > 0, 'dir() should return path string');
  assert.ok(typeof o.cleanup === 'function', 'dir() should return cleanup function');
  assert.ok(fs.existsSync(o.path), 'temporary directory should exist on disk');
  assert.ok(fs.statSync(o.path).isDirectory(), 'path should be a directory');

  await o.cleanup();
  assert.strictEqual(fs.existsSync(o.path), false, 'cleanup() should remove temporary directory');
}

async function testWithFile() {
  let observedPath = '';
  const result = await withFile(async ({ path, fd }) => {
    observedPath = path;
    assert.ok(typeof path === 'string' && path.length > 0, 'withFile should provide path');
    assert.ok(typeof fd === 'number', 'withFile should provide file descriptor');
    assert.ok(fs.existsSync(path), 'temporary file should exist inside withFile callback');
    fs.writeSync(fd, Buffer.from('inside withFile'));
    return 'file-done';
  }, { prefix: 'with-file-' });

  assert.strictEqual(result, 'file-done', 'withFile should return callback result');
  assert.strictEqual(fs.existsSync(observedPath), false, 'withFile should automatically clean up file');
}

async function testWithDir() {
  let observedPath = '';
  const result = await withDir(async ({ path }) => {
    observedPath = path;
    assert.ok(typeof path === 'string' && path.length > 0, 'withDir should provide path');
    assert.ok(fs.existsSync(path), 'temporary directory should exist inside withDir callback');
    assert.ok(fs.statSync(path).isDirectory(), 'path should be a directory inside withDir callback');
    return 'dir-done';
  }, { prefix: 'with-dir-', unsafeCleanup: true });

  assert.strictEqual(result, 'dir-done', 'withDir should return callback result');
  assert.strictEqual(fs.existsSync(observedPath), false, 'withDir should automatically clean up directory');
}

async function run() {
  await testFile();
  await testDir();
  await testWithFile();
  await testWithDir();
  console.log('Contract passed: all tmp-promise assertions verified');
}

run();

Ursprungs-Seeder

anonym