---
name: Bun File I/O
slug: bun-file-i-o
category: DevOps
description: "Bun File I/O covers the preferred file-reading, writing, scanning, and deletion patterns used in this repo. Use it when working on file operations or directory handling with Bun and node:fs helpers."
github: "https://github.com/CyberStrikeus/CyberStrike/tree/main/.cyberstrike/skill/bun-file-io"
language: TypeScript
stars: 1746
forks: 269
install: "npx degit https://github.com/CyberStrikeus/CyberStrike/tree/main/.cyberstrike/skill/bun-file-io ~/.claude/skills/bun-file-io"
installs_to: ~/.claude/skills/bun-file-io
source_path: .cyberstrike/skill/bun-file-io/SKILL.md
collection_size: 51
category_size: 798
collection_url: "https://dirskills.com/collections/CyberStrikeus/CyberStrike"
added: 2026-08-12T04:43:16.050Z
last_synced: 2026-08-12T04:43:16.050Z
canonical_url: "https://dirskills.com/skills/bun-file-i-o"
---

# Bun File I/O

Bun File I/O covers the preferred file-reading, writing, scanning, and deletion patterns used in this repo. Use it when working on file operations or directory handling with Bun and node:fs helpers.

**Install:**

```bash
npx degit https://github.com/CyberStrikeus/CyberStrike/tree/main/.cyberstrike/skill/bun-file-io ~/.claude/skills/bun-file-io
```

## README

## Use this when

- Editing file I/O or scans in `packages/cyberstrike`
- 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.
