Browser-compatible TypeScript library for parsing Mac resource forks - Extract and convert with Result/Err error handling
npm install @lachlanbwwright/rsrcdump-tsTypeScript library for parsing and creating Macintosh resource forks. Browser-compatible with no Node.js dependencies.
- ๐ Browser Compatible - Works in browsers and Node.js (no fs dependencies in core library)
- ๐ Type Safe - Strict TypeScript with noUncheckedIndexedAccess
- โ
Error Handling - Result/Err pattern (no exceptions for control flow)
- ๐ฆ Small Bundle - 21.2 kB gzipped
- ๐งช Well Tested - 69 tests, 100% pass rate
- ๐ TypeScript Type Generation - Generate .d.ts files from struct specs
- ๐จ JSON Struct Specs - Define struct specs in elegant JSON format
- โก Backtick Array Optimization - Compact array representation for repeated fields
``bash`
npm install @lachlanwright/rsrcdump-ts
`typescript
import { load, saveToJson, isOk } from '@lachlanwright/rsrcdump-ts';
// Load file using File API
const file = await fileInput.files[0].arrayBuffer();
const data = new Uint8Array(file);
// Parse resource fork
const result = load(data);
if (isOk(result)) {
const fork = result.value;
console.log(Loaded ${fork.tree.size} resource types);`
// Convert to JSON
const jsonResult = await saveToJson(data, []);
if (isOk(jsonResult)) {
const jsonString = jsonResult.value;
// Use the JSON...
}
}
`typescript
import { readFile } from 'fs/promises';
import { load, saveToJson, isOk } from '@lachlanwright/rsrcdump-ts';
// Load file
const fileData = await readFile('file.rsrc');
const data = new Uint8Array(fileData);
// Parse resource fork
const result = load(data);
if (isOk(result)) {
const fork = result.value;
console.log(Loaded ${fork.tree.size} resource types);`
}
- load(data: Uint8Array) - Parse resource fork from bytes
- saveToJson(data, specs?, include?, exclude?, options?) - Convert to JSON
- loadBytesFromJson(json, specs?, only?, skip?, adf?) - Convert JSON back to bytes
- generateTypesFromSpecs(specs) - Generate TypeScript type definitions
- generateTypeFromTemplate(template, typeName?) - Generate type from single template
- parseJsonSpecs(jsonData) - Parse struct specs from JSON
- jsonSpecToString(spec) - Convert single JSON spec to string format
- jsonSpecsToStrings(specs) - Convert multiple JSON specs
- resourceForkFromBytes(data) - Low-level parse
- packResourceFork(fork) - Low-level pack
- resourceForkToJsonString(fork, ...) - Convert fork to JSON
See the examples/ directory for complete examples:
- examples/basic-usage.ts - Basic usage patternsexamples/advanced-usage.ts
- - Advanced featuresexamples/type-generation.ts
- - TypeScript type generationexamples/json-specs.ts
- - JSON struct spec format
- API Reference - Complete API documentation
- Quick Reference - Common operations
- FAQ - Frequently asked questions
- New Features - Advanced features guide
- Testing - Testing guide
- Development - Contributing guide
- Result Type - Error handling pattern
The package includes a CLI tool for Node.js:
`bashExtract to JSON
npm run cli extract input.rsrc output.json [struct-specs.txt]
Browser Compatibility
The core library has zero Node.js dependencies and works in any modern browser. The only requirement is ES2020+ support.
$3
โ
All parsing and conversion functions
โ
Type generation (returns string, you save it)
โ
JSON operations
โ
Struct template parsing
โ
Result/Err error handling
$3
โ ๏ธ CLI tool (
src/cli.ts`)Tested on EarthFarm.ter.rsrc (159 KB):
- Load: 3-8 ms
- JSON Conversion: 18-29 ms
- Round-trip: 38-54 ms
MIT
See CONTRIBUTING.md for guidelines.