4.4 KiB
Why
The drive VFS already abstracts file operations behind a structural DriveStorage view, but there is no way to mount a compressed archive (zip, tar, gz, tgz, rar, 7z) as a drive. Users routinely receive bundles whose extension lies about the real compression (a .zip that is actually a 7z stream, a .tar.gz renamed .bin) or whose contents are split across multi-volume sets (.part1.rar/.r00–.r99, .7z.001–.7z.NNN, multi-file split-zip). Treating those archives as first-class drives lets every existing drive consumer (sharing, hydrate-from, file-operations, plugins) browse, read, and (where the format permits) write archive contents without ad-hoc extraction.
What Changes
- Add a shared
@suaveplan/drive-storage-archive-corepackage: format sniffing by magic bytes (extension is advisory only), split-volume reassembly, central-directory caching, password/encryption hook contract, and a streamingEntryReaderabstraction so per-format adapters only implement the format-specific decode path. - Add six per-format storage adapters, each implementing the
DriveStoragecontract over an underlyingAbstractStorage(or raw byte source) holding the archive bytes:@suaveplan/drive-storage-zip— ZIP / ZIP64 / split-zip (.z01–.zNN+.zip), read-write with rewrite-on-flush.@suaveplan/drive-storage-tar— POSIX/USTAR/PAX, sparse files, long-name extensions; read-write (append + rewrite on delete).@suaveplan/drive-storage-gz— single-stream gzip wrapping one logical entry; read-write.@suaveplan/drive-storage-tgz— composition oftarovergz(and.tar.bz2,.tar.xz,.tar.zstvia pluggable codec); read-mostly, write via full rewrite.@suaveplan/drive-storage-rar— RAR4 + RAR5 + multi-volume (.partN.rar, legacy.r00–.r99); read-only (writing RAR is patent-encumbered).@suaveplan/drive-storage-7z— 7z LZMA/LZMA2/BCJ filters + multi-volume (.7z.001–.7z.NNN); read-write via rewrite-on-flush.
- Public factory
openArchiveStorage(source, { format?, password?, splitParts?, mode? })that auto-detects format from magic bytes, discovers split volumes through a sibling-resolver callback on the host storage, and returns aDriveStorageready to hand tonew Drive(...). - Mode flags:
read-only|copy-on-write(in-memory overlay, materialise onflush()) |rewrite(write directly back through host storage on each mutation). RAR is locked toread-only. - Error codes namespaced per package (
ARCHIVE_*,ZIP_*,TAR_*,GZ_*,RAR_*,SEVENZ_*) registered in each package's error registry.
Capabilities
New Capabilities
drive-storage-archive-core: shared format sniffing, split-volume reassembly, mode/flush contract, password hook, codec registry, error taxonomy, and conformance harness all per-format adapters run against.drive-storage-zip: ZIP/ZIP64/split-zip adapter exposing archive entries as aDriveStorage.drive-storage-tar: POSIX/USTAR/PAX tar adapter exposing tar entries as aDriveStorage.drive-storage-gz: single-entry gzip adapter exposing the wrapped stream as aDriveStorage.drive-storage-tgz: composed tar-over-codec adapter (gzip/bzip2/xz/zstd) exposing entries as aDriveStorage.drive-storage-rar: read-only RAR4/RAR5 + multi-volume adapter exposing rar entries as aDriveStorage.drive-storage-7z: 7z + multi-volume adapter exposing 7z entries as aDriveStorage.
Modified Capabilities
None — drive's DriveStorage view is already satisfied; no requirement changes to existing specs.
Impact
- New packages under
packages/drive/drive-storage-{zip,tar,gz,tgz,rar,7z}pluspackages/drive/drive-storage-archive-core(seven total). All universal-tier where the codec is pure-TS, server-tier where native bindings are needed (RAR, optionally 7z LZMA SDK). - New dependencies on pure-TS codec libraries via Bun catalog (
fflatefor deflate,pakofallback,lzma-nativeor wasmlzma,xz-decompress,@zip.js/zip.jsis not used — we implement directly for streaming + split support). - Drive consumers (
drive-sharing,drive-template,drive-react-sharing) gain transparent archive browsing with no API changes. - Bin: optional
suaveplan-archiveCLI indrive-storage-archive-corefor listing/extracting any supported archive from the shell. (Decision deferred to design.md.) - Test surface:
runArchiveConformanceharness indrive-storage-archive-core/testingexercised by all six adapters.