lightdrift-libraw decodes camera RAW data locally inside Node.js. Supported
systems install a prebuilt native addon, so the first decode does not require a
compiler or a separate LibRaw installation.
- Node.js 22 or 24.
- Linux glibc x64/arm64, macOS x64/arm64, or Windows x64.
- A complete RAW file or buffer. The stable API is not an incremental stream decoder.
If a prebuilt binary is unavailable, follow the documented source-build fallback.
Install the stable release from the default latest dist-tag:
npm install lightdrift-librawConfirm that the JavaScript package and native addon load:
node -e "const { LibRaw } = require('lightdrift-libraw'); console.log(LibRaw.version())"Expected output:
0.22.2
This example decodes a RAW file, resizes it inside the output bounds, encodes a JPEG, and writes the copied result buffer to disk.
import { writeFile } from "node:fs/promises";
import { LibRaw, LibRawError } from "lightdrift-libraw";
const raw = new LibRaw();
try {
await raw.loadFile("photo.nef");
const image = await raw.createJPEGBuffer({
width: 1920,
height: 1920,
quality: 85,
progressive: true,
});
await writeFile("photo.jpg", image.data);
console.log(`${image.width}x${image.height} · ${image.size} bytes`);
} catch (error) {
if (error instanceof LibRawError) {
console.error(error.code, error.operation, error.state);
}
throw error;
} finally {
await raw.close();
}loadFile() performs recycle → open → unpack. Use openFile() followed by an
explicit unpack() only when you need upstream LibRaw lifecycle semantics.
const { writeFile } = require("node:fs/promises");
const { LibRaw, LibRawError } = require("lightdrift-libraw");
async function convert(input, output) {
const raw = new LibRaw();
try {
await raw.loadFile(input);
const image = await raw.createWebPBuffer({ width: 1600, quality: 82 });
await writeFile(output, image.data);
return image;
} catch (error) {
if (error instanceof LibRawError) {
console.error(error.code, error.operation, error.state);
}
throw error;
} finally {
await raw.close();
}
}
convert("photo.arw", "photo.webp");loadBuffer() copies the input into worker-owned memory. The input remains
valid for native operations until recycle() or close() releases it.
import { readFile } from "node:fs/promises";
import { LibRaw } from "lightdrift-libraw";
const bytes = await readFile("photo.dng");
const raw = new LibRaw();
try {
await raw.loadBuffer(bytes);
const metadata = await raw.getMetadata();
const thumbnail = await raw.createThumbnailJPEGBuffer({
width: 480,
height: 480,
quality: 80,
});
console.log(metadata.make, metadata.model, thumbnail.size);
} finally {
await raw.close();
}All stable encoders return the same result shape:
interface EncodedImageResult {
data: Buffer;
format: "jpeg" | "png" | "tiff" | "webp" | "avif" | "ppm";
width: number;
height: number;
channels: number;
size: number;
processingTimeMs: number;
source: "processed" | "embedded-thumbnail";
}data is owned by JavaScript. source tells you whether the result came from
the processed RAW image or an embedded camera thumbnail.
Stateful operations accept an AbortSignal:
import { LibRaw, LibRawError } from "lightdrift-libraw";
const raw = new LibRaw();
const controller = new AbortController();
const decoding = raw.loadFile("large.raw", { signal: controller.signal });
controller.abort("no longer needed");
try {
await decoding;
} catch (error) {
if (!(error instanceof LibRawError) || error.code !== "ABORT_ERR") throw error;
} finally {
await raw.close();
}An aborted operation rejects with LibRawError and code === "ABORT_ERR".
Read Lifecycle, events, and cancellation for queued and active
cancellation semantics.
- Browse formats and cameras.
- Learn lifecycle and concurrency.
- Review the safe LibRaw API mapping.
- Convert a beta application with the v1 migration guide.
- Project README — Capabilities and common workflows.
- Platform support — Prebuild matrix and exclusions.
- Source builds — Compiler-based fallback.