@bazariodev/baler
v0.1.0
Published
Dependency-free ZIP creation with portable filenames and input limits.
Readme
@bazariodev/baler
Baler creates ZIP archives from named text files. It checks portable filenames, duplicate names, input size, and classic ZIP limits.
Install
pnpm add @bazariodev/balerThere are no runtime or peer dependencies. Node.js support is
^22.12.0 || ^24.0.0 || >=26.0.0. Browser and worker runtimes need Blob,
TextEncoder, and typed arrays. Compression uses native Web APIs when available.
Usage
import { balingZip } from '@bazariodev/baler';
const blob = await balingZip([
{ name: 'results.txt', content: 'Completed: 42\n' },
{ name: 'settings.json', content: JSON.stringify({ mode: 'sample' }) },
]);The result is a Blob with type application/zip. The application owns saving,
downloading, or sending this Blob.
Pass { maxInputSize: 1_000_000 } as the second argument to set an input limit.
Each call has separate archive data. Calls can overlap, including calls that use
the same options object.
Behavior
- Files contain text. Names and content use UTF-8. Empty files are included. An empty file list produces an empty ZIP. File order is preserved.
- Input files are copied before compression starts. Later changes to the supplied array or file objects do not change the archive.
- Filenames must be nonempty, valid Unicode, and at most 255 UTF-8 bytes.
Paths, control characters, Windows device names, forbidden filename characters,
and trailing spaces or periods are rejected. Names must be distinct after NFC
normalization and conversion to lowercase. The original spelling is preserved.
Device names with spaces before the extension, such as
CON .txt, are also rejected. - No filename is reserved by Baler. Applications can include
manifest.json. - The default input limit is 32,000,000 UTF-8 bytes across all file content. Names and ZIP headers do not count toward this limit. Input validation completes before compression starts. This limit does not bound heap use or native copies.
- Each file's content is encoded once. Text that exceeds the remaining input limit by character count is rejected before encoding. The final check uses UTF-8 bytes.
- Use ZIP method 8 when native
CompressionStream('deflate-raw')succeeds. If compression is absent, unsupported, or fails, use ZIP method 0 for that file. See MDN CompressionStream. - Entries use the fixed modification date 1980-01-01 at 00:00:00. Baler does not copy filesystem timestamps or use the current time.
- CRC-32, local headers, and the central directory describe each file. The archive must have fewer than 65,535 files and fewer than 4,294,967,295 bytes. ZIP64, directory entries, binary input, encryption, and archive reading are not supported.
API
| Function | Result |
| --- | --- |
| balingZip(files, options?) | Promise<Blob> containing one independent ZIP archive. |
| validateFileNames(names) | Check an array of filenames; return void on success. |
| validateZipOptions(options?) | Check options synchronously and return the resolved input limit in bytes. |
| Input | Meaning |
| --- | --- |
| files | Readonly array of { name: string, content: string }. |
| options.maxInputSize | Positive safe integer. Maximum total UTF-8 content bytes. Default: 32,000,000. |
| names | Readonly array of filenames to check before application work starts. |
balingZip validates its input. To reserve a filename in an application,
pass that name and the requested names to validateFileNames before building files.
Use validateZipOptions to reject invalid options before other application work starts.
The default limit and its validation stay in Baler.
Errors
validateFileNames throws TypeError for invalid or duplicate names.
validateZipOptions throws TypeError for an invalid input limit.
balingZip rejects with TypeError for invalid files, names, content, or options.
It rejects with RangeError when input size or a classic ZIP limit is exceeded.
Native allocation failures can also reject the operation.
TypeScript
import { balingZip, type ZipFile } from '@bazariodev/baler';
const files: readonly ZipFile[] = [{ name: 'results.txt', content: 'ready' }];
const archive: Promise<Blob> = balingZip(files);The package exports ZipFile and BalingZipOptions types. Use ES2022 and the DOM
or WebWorker library types. ESM and CommonJS outputs have matching declarations.
License
MIT.
