Skip to main content

Crate decmpfs

Crate decmpfs 

Source
Expand description

decmpfs — apply the operating system’s transparent per-file compression to a file in place: macOS APFS (decmpfs), Linux btrfs, Windows NTFS. The kernel decompresses on read, so the file keeps its logical size + exact contents and loads at near-native speed while taking less space on disk.

compress_file(path) detects the filesystem, applies compression, then verifies the kernel reads the bytes back identically — rolling back on any failure. probe(path) is the detect-only / capability-reporting half.

Backends: btrfs (FS_COMPR_FL + the btrfs.compression property), NTFS (FSCTL_SET_COMPRESSION), and macOS decmpfs (resource fork, kernel-roundtrip verified); other targets report Unsupported.

Contract: every Outcome is a SUCCESS; Err is reserved for genuine I/O failures that leave the file’s integrity unknown. An unsupported FS, a permission/lock issue, an incompressible or too-large file are non-fatal Outcomes.

Panic-free invariant: the deny below keeps non-test code free of the obvious panic sources; all slice indexing is length-guarded.

Structs§

DecmpfsWriter
An atomic incremental writer for OS-transparent filesystem compression.
Gate
The install-time gate: an optional glob AND an optional size predicate. A file matches only if BOTH present predicates pass (an absent half is vacuously true). Gate::default() is the fleet default — glob **/*.node, no size floor.
RmOptions
Node fs.rm options — same four fields, same defaults, nothing extra.
Stat
Filesystem-compression state of a path — one call that coalesces the otherwise-separate size + backend-signal reads (the compress/copy paths previously did a stat AND an lstat/attr read per file). Follows symlinks: compression is a property of the target file, never a symlink.

Enums§

CopyOutcome
What a copy_file did — a SUCCESS shape, same contract as Outcome: Err is reserved for genuine I/O failures; the copy itself always lands.
Error
Genuine failures only. A capability/permission gap is an Outcome, not an Error.
GateParseError
Why a Gate / SizePredicate string failed to parse.
Outcome
What happened to the file. Only Err is a hard failure.
SizePredicate
A >/>= comparison against a byte threshold.
SkipReason
Support
UnsupportedReason

Constants§

DEFAULT_GLOB
The fleet default — every native addon, regardless of size.

Functions§

compress_bytes
THE install-time entry point: write content to path as an OS-compressed file in ONE pass — never a write-then-read-back-recompress.
compress_file
THE entry point: detect → gate → apply → verify → rollback-on-failure. Idempotent. Never panics. Never corrupts the file.
copy_file
Copy src to dest preserving transparent filesystem compression — the fs.copyFile the OS never shipped. A plain byte copy silently re-inflates a compressed file (the kernel hands every reader the full logical bytes, and that is what gets written back out); this copy keeps the on-disk savings.
probe
Detect-only, no mutation — for dry-run / capability reporting.
rm
Node fs.rm(path, options). A file/symlink is a single unlink. A directory needs recursive (else EISDIR, as in Node); recursive delete is std::fs::remove_dir_all — MEASURED as the floor on APFS.
stat
Inspect the FS-compression state of path (see Stat).
try_clone_file
Attempt a copy-on-write clone of src at dest (clonefile(2) on macOS, the FICLONE ioctl on Linux) — the zero-cost way to copy a compressed file WITH its compression. Ok(true) = cloned; Ok(false) = this pairing can’t clone (cross-volume, non-reflink FS, an existing destination on macOS, Windows) and the caller decides the fallback — copy_file is the clone-then-fallback composition, and a Node-COPYFILE_FICLONE_FORCE-shaped caller turns false into its error.