desktop-zip-extractor
Extracts a ZIP archive to disk using only Node’s zlib — with no third-party unzip dependency.
It exists for one measured reason. The dependency it replaced on this path, adm-zip, bundled roughly 34 KB of minified JavaScript into EVERY Obsidian plugin built with this library: a plugin ships a single CJS main.js, esbuild has no code splitting to put a dependency behind, and a await import() only defers evaluation — the module body is inlined either way. node:zlib is already an esbuild external, so the same work now costs a plugin bundle nothing at all. Archives are still WRITTEN with adm-zip at release time (script-utils/demo-vault.ts), which is Node-side tooling and never reaches a plugin bundle.
Deliberately narrow: it reads exactly what that writer produces — stored and deflated entries in an unencrypted archive below the 4 GB / 65535-entry ZIP64 threshold — and raises a named error for anything else rather than guessing at it. Sizes and offsets are taken from the central directory, which is authoritative even for archives written with data descriptors.
The node: imports below are safe to merely EVALUATE on mobile — require hands back undefined there and nothing reads it at load time — so this module can sit in the generated barrels without breaking the library’s load on Android. Only the calls are desktop-only.
Interfaces
Section titled “Interfaces”| Interface | Description |
|---|---|
| ExtractZipArchiveParams | Parameters for extractZipArchive. |
| ZipExtractionFileSystem | The slice of node:fs extraction needs. Only the two WRITING calls are required, and that is deliberate: Electron’s asar layer intercepts fs READS (and existsSync) on any path containing .asar, which a demo vault may legitimately ship as a plain file. Never probing the target with a read keeps that interception out of the picture entirely, and a caller that hands over Electron’s original-fs is safe even from the write side. |
| ZipExtractionMkdirOptions | The options ZipExtractionFileSystem.mkdirSync is always called with. Extraction never probes for an existing directory, so every call has to create the missing parents itself and tolerate a directory that is already there. |
Functions
Section titled “Functions”| Function | Description |
|---|---|
| extractZipArchive | Extracts every entry of a ZIP archive into a directory. Directory entries become directories; a file entry’s parents are created whether or not the archive declared them. An entry whose name would escape ExtractZipArchiveParams.targetDirectory is refused rather than written (the “zip slip” traversal), as is an encrypted, ZIP64, or unknown-compression archive. |