mcpField
B
bun-file-io

bun-file-io

github.com/anomalycoDevelopment225.5k105 installsUpdated today
Repository

About bun-file-io

A development skill documenting file I/O and scanning conventions for Bun-based work in `packages/opencode`. It helps contributors choose APIs for file access, directories, scans, and external processes.

Key features

  1. 01Bun file reading and writing patterns
  2. 02File scans with Bun.Glob
  3. 03Directory operations with node:fs/promises
  4. 04External tools with Bun.which and Bun.spawn
  5. 05Stream output decoding guidance

Use cases

  1. 01Editing file I/O in `packages/opencode`
  2. 02Scanning files and directories
  3. 03Reading binary or large files
  4. 04Running external tools and handling output

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/anomalyco/opencode --skill bun-file-io

After installing, type/bun-file-ioin Claude Code to confirm it loaded.

Details

From the project README

Use this when

  • Editing file I/O or scans in packages/opencode
  • Handling directory operations or external tools

Bun file APIs (from Bun docs)

  • Bun.file(path) is lazy; call text, json, stream, arrayBuffer, bytes, exists to read.
  • Metadata: file.size, file.type, file.name.
  • Bun.write(dest, input) writes strings, buffers, Blobs, Responses, or files.
  • Bun.file(...).delete() deletes a file.
  • file.writer() returns a FileSink for incremental writes.
  • Bun.Glob + Array.fromAsync(glob.scan({ cwd, absolute, onlyFiles, dot })) for scans.
  • Use Bun.which to find a binary, then Bun.spawn to run it.
  • Bun.readableStreamToText/Bytes/JSON for stream output.

When to use node:fs

  • Use node:fs/promises for directories (mkdir, readdir, recursive operations).

Repo patterns

  • Prefer Bun APIs over Node fs for file access.
  • Check Bun.file(...).exists() before reading.
  • For binary/large files use arrayBuffer() and MIME checks via file.type.
  • Use Bun.Glob + Array.fromAsync for scans.
  • Decode tool stderr with Bun.readableStreamToText.
  • For large writes, use Bun.write(Bun.file(path), text).

NOTE: Bun.file(...).exists() will return false if the value is a directory. Use Filesystem.exists(...) instead if path can be file or directory

Quick checklist

  • Use Bun APIs first.
  • Use path.join/path.resolve for paths.
  • Prefer promise .catch(...) over try/catch when possible.

Comments

Markdown supported