https://github.com/ije/esar
Bundle multiple files into a single binary blob.
https://github.com/ije/esar
Last synced: 2 months ago
JSON representation
Bundle multiple files into a single binary blob.
- Host: GitHub
- URL: https://github.com/ije/esar
- Owner: ije
- License: mit
- Created: 2024-06-28T11:23:01.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-06-25T10:48:05.000Z (12 months ago)
- Last Synced: 2025-10-05T19:55:08.947Z (8 months ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# esar
A tiny library for bundling multiple files into a single binary blob.
```js
import { Archive, bundle } from "esar";
// or import from esm.sh in browser
// import { Archive, bundle } from "https://esm.sh/esar";
// bundle some files
const data = bundle([
new File(["bar"], "foo.txt", { type: "text/plain" }),
new File(["foo"], "bar.txt", { type: "text/plain" }),
]);
// read the archive
const archive = new Archive(data);
archive.checksum; // a 32-bit checksum of the archive
const entries = archive.entries()
entries.length; // => 2
entries[0].name; // => "foo.txt"
entries[0].type; // => "text/plain"
entries[1].name; // => "bar.txt"
entries[1].type; // => "text/plain"
archive.file("foo.txt"); // => File(["bar"], "foo.txt", { type: "text/plain" })
archive.file("bar.txt"); // => File(["foo"], "bar.txt", { type: "text/plain" })
```
## Compression
This library does not compress the archived files. Below is an example of how to use `CompressionStream` to compress data
with `gzip` algorithm, and use `DecompressionStream` to decompress the data again.
```js
import { Archive, bundle } from "esar";
const data = bundle([/* add some files */]);
// compress and decompress the data
const compressed = await readAll(new Blob([data]).stream().pipeThrough(new CompressionStream("gzip")));
const decompressed = await readAll(new Blob([compressed]).stream().pipeThrough(new DecompressionStream("gzip")));
```
> Note that `CompressionStream` and `DecompressionStream` are not supported in all browsers, and you may need to use a
> polyfill or a different compression algorithm depending on your requirements.