ProvenPin Install

adm-zip buffer roundtrip: working versions (tested 2026-10-16)

Build an in-memory zip from string and buffer entries, write it to a temp file or buffer, then read it back with AdmZip to assert entry names and text contents offline.

passed4 passed · 0 failed2026-10-16 02:18 UTC
Status
passed
Last passed
2026-10-16 02:18 UTC
Tests
4 / 4
Language
TypeScript
Runtime
node v22.23.3
pinned versions4
adm-zip@0.6.1@types/adm-zip@0.6.0@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false
npm test
test environment
node v22.23.3
linux 6.17.0-1022-azure
x64
runner: github-actions 38839686104

The code

Exactly the files that passed. Your agent can pull them with get_recipe("adm-zip-roundtrip") (install), or see them on GitHub.

package.json
{
  "name": "adm-zip-roundtrip",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node --import tsx --test test/*.test.ts"
  },
  "dependencies": {
    "adm-zip": "0.6.1"
  },
  "devDependencies": {
    "@types/adm-zip": "0.6.0",
    "@types/node": "26.6.5",
    "tsx": "4.23.15"
  }
}
src/archive.ts
import AdmZip from "adm-zip";

export type EntryInput = { path: string; data: string | Buffer };

function toContent(data: string | Buffer): Buffer {
  return typeof data === "string" ? Buffer.from(data, "utf8") : data;
}

export function buildZip(entries: EntryInput[]): AdmZip {
  const zip = new AdmZip();
  for (const entry of entries) {
    zip.addFile(entry.path, toContent(entry.data));
  }
  return zip;
}

export function pack(entries: EntryInput[]): Buffer {
  return buildZip(entries).toBuffer();
}

export function writeZip(entries: EntryInput[], targetPath: string): string {
  buildZip(entries).writeZip(targetPath);
  return targetPath;
}

export function openArchive(source: Buffer | string): AdmZip {
  return new AdmZip(source as string);
}

export function listEntries(source: Buffer | string): string[] {
  return openArchive(source)
    .getEntries()
    .map((entry) => entry.entryName);
}

export function readAsText(source: Buffer | string, entryPath: string): string {
  const entry = openArchive(source).getEntry(entryPath);
  if (!entry) {
    throw new Error(`entry not found: ${entryPath}`);
  }
  return entry.getData().toString("utf8");
}
test/archive.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { mkdtemp, readFile, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import {
  listEntries,
  openArchive,
  pack,
  readAsText,
  writeZip,
} from "../src/archive.ts";

test("roundtrips string entries through a buffer", () => {
  const buf = pack([
    { path: "hello.txt", data: "hello world" },
    { path: "nested/data.json", data: JSON.stringify({ ok: true }) },
  ]);

  assert.deepEqual(listEntries(buf).sort(), ["hello.txt", "nested/data.json"]);
  assert.equal(readAsText(buf, "hello.txt"), "hello world");
  assert.equal(readAsText(buf, "nested/data.json"), '{"ok":true}');
});

test("stores folder entries and raw buffers", () => {
  const bytes = Buffer.from([0x00, 0x01, 0x02, 0xff]);
  const buf = pack([
    { path: "assets/", data: "" },
    { path: "assets/logo.bin", data: bytes },
  ]);

  assert.deepEqual(listEntries(buf).sort(), ["assets/", "assets/logo.bin"]);
  const entry = openArchive(buf).getEntry("assets/logo.bin");
  assert.ok(entry);
  assert.deepEqual(entry.getData(), bytes);
  assert.deepEqual(readAsText(buf, "assets/"), "");
});

test("writes a zip to a temp path and reads it back", async () => {
  const dir = await mkdtemp(join(tmpdir(), "adm-zip-"));
  try {
    const target = join(dir, "archive.zip");
    writeZip(
      [
        { path: "a.txt", data: "alpha" },
        { path: "b.txt", data: "beta" },
      ],
      target,
    );

    const raw = await readFile(target);
    assert.deepEqual(listEntries(target).sort(), ["a.txt", "b.txt"]);
    assert.equal(readAsText(raw, "a.txt"), "alpha");
    assert.equal(readAsText(target, "b.txt"), "beta");
  } finally {
    await rm(dir, { recursive: true, force: true });
  }
});

test("throws for a missing entry", () => {
  const buf = pack([{ path: "only.txt", data: "x" }]);
  assert.throws(() => readAsText(buf, "missing.txt"), /entry not found/);
});

Connect to ProvenPin

Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.

terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp

Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.