packfile
@johnhenry/packfile compresses a directory tree into a single archive
— gzip(application/webbundle), via the real
wbn package —
and serves that archive as HTTP responses through the
(Request) => Response handler pattern shared across this family.
Previously developed as
lemem, never published under that name. Now@johnhenry/packfile, starting at0.0.0.
Install
Section titled “Install”npm install @johnhenry/packfileQuick example
Section titled “Quick example”import { fromDirectory, toArchive, createRouter } from '@johnhenry/packfile';
const files = await fromDirectory('./static');const archive = await toArchive(files);
// later, from the archive alone:import { fromArchive } from '@johnhenry/packfile';const restored = await fromArchive(archive);const handler = createRouter(restored, { alias: { "/": "index.html" } });
const response = await handler(new Request("http://localhost/"));Or from the CLI:
npx packfile compress ./static ./compiled.wbnnpx packfile serve ./compiled.wbn 8080Family
Section titled “Family”packfile isn’t a standalone compiler/server so much as the designed consumer of one sibling package’s archive output, and a drop-in handler for another’s router:
- fileable — fileable’s
<Dir encode="wbn">renders a JSX subtree straight to agzip(application/webbundle)archive, via the samewbnpackage packfile itself depends on — not via a dependency on packfile. The resulting.wbnis directly readable by this package’s ownfromArchive()and servable viacreateRouter(), no unpacking to disk needed. @johnhenry/servable—createRouter()returns a(Request | path, ctx?) => Responsehandler (aliased as.fetch), the exact shape servable’sRoute’shandlerprop accepts. Mounting a packfile-served directory inside a servable app is just passing a function.- andbox — packfile’s Blob Preview
mode is a real, direct npm dependency on
@johnhenry/andbox: it delegates JS module-specifier resolution to andbox’screateVirtualModuleRegistry()rather than reimplementing it. This is the same technical link that puts packfile on andbox’s accent hue on this site (see this site’sREADME.mdhue registry if you’re curious why).
The pages here
Section titled “The pages here”- API —
fromDirectory,toArchive,fromArchive,createRouter, hashing, caching middleware, browser usage - CLI —
compress,decompress,serve - Blob preview — host packaged content in a browser tab/iframe with no server at all
- Web Bundle / IWA primitives — the lower-level
toWebBundle/fromWebBundle/createWebBundleRouterAPI, for real Isolated Web App deployment
Internal data formats — the FileEntry/FilesMap table, the archive byte
format, hashing, and how the two gzip implementations (Node/browser) relate
— are documented precisely in
FORMATS.md
in the repo.
License
Section titled “License”MIT