Commit 4258e94
committed
zlib,vfs: add ZIP archive support
Add ZIP archive read/write support to zlib, plus a VFS provider that
mounts a ZIP archive as a browsable, read/write file system.
zlib gains three classes and a pair of helper functions:
* ZipEntry represents a single archive member: name, metadata, and
content, created from a Buffer/stream (`create()`/`createStream()`)
or read back out of raw entry bytes (`read()`). It is otherwise
immutable; every accessor and static creator has a synchronous and
an asynchronous form.
* ZipFile wraps a real ZIP file on disk (`open()`/`openSync()`),
exposing get/add/delete/stream by name plus `compact()` to reclaim
space left behind by deleted entries. Opened read-only unless
`{ writable: true }` is passed.
* ZipBuffer is the equivalent fully in-memory representation,
serializable back to a Buffer with `toBuffer()`/`toBufferSync()`.
Always writable, since nothing is written until asked to serialize.
* `createZipArchive()`/`createZipArchiveSync()` build a brand-new
archive (as a stream or a Buffer) from a list of entries.
Every read path enforces `getMaxZipContentSize()`/
`setMaxZipContentSize()` limits and rejects malformed local/central
directory records, guarding against zip-bomb and corrupt-archive
inputs. New ERR_ZIP_* error codes cover corrupt entries, missing
entries, oversized entries, invalid archives, non-writable archives,
and unsupported ZIP features.
node:vfs gains ArchiveProvider, a VirtualProvider backed by an
already-open ZipBuffer or ZipFile: mounting one exposes the archive's
entries through the same fs-like API any other VFS provider offers.
Directories are inferred from entry-name prefixes rather than stored
explicitly. Because a ZIP member can only be written or read in full,
never edited in place, a file opened for writing is buffered and only
committed as a new archive entry when its handle is closed. The
provider's readonly flag mirrors the underlying archive's own
writable state.
Signed-off-by: Philipp Dunkel <pip@pipobscure.com>1 parent f91697a commit 4258e94
19 files changed
Lines changed: 5572 additions & 4 deletions
File tree
- doc/api
- lib
- internal
- vfs/providers
- test
- parallel
- pummel
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3674 | 3674 | | |
3675 | 3675 | | |
3676 | 3676 | | |
| 3677 | + | |
| 3678 | + | |
| 3679 | + | |
| 3680 | + | |
| 3681 | + | |
| 3682 | + | |
| 3683 | + | |
| 3684 | + | |
| 3685 | + | |
| 3686 | + | |
| 3687 | + | |
| 3688 | + | |
| 3689 | + | |
| 3690 | + | |
| 3691 | + | |
| 3692 | + | |
| 3693 | + | |
| 3694 | + | |
| 3695 | + | |
| 3696 | + | |
| 3697 | + | |
| 3698 | + | |
| 3699 | + | |
| 3700 | + | |
| 3701 | + | |
| 3702 | + | |
| 3703 | + | |
| 3704 | + | |
| 3705 | + | |
| 3706 | + | |
| 3707 | + | |
| 3708 | + | |
| 3709 | + | |
| 3710 | + | |
| 3711 | + | |
| 3712 | + | |
| 3713 | + | |
| 3714 | + | |
| 3715 | + | |
| 3716 | + | |
| 3717 | + | |
| 3718 | + | |
| 3719 | + | |
| 3720 | + | |
3677 | 3721 | | |
3678 | 3722 | | |
3679 | 3723 | | |
| |||
4617 | 4661 | | |
4618 | 4662 | | |
4619 | 4663 | | |
| 4664 | + | |
| 4665 | + | |
4620 | 4666 | | |
4621 | 4667 | | |
4622 | 4668 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
| |||
304 | 306 | | |
305 | 307 | | |
306 | 308 | | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
307 | 358 | | |
308 | 359 | | |
309 | 360 | | |
| |||
318 | 369 | | |
319 | 370 | | |
320 | 371 | | |
| 372 | + | |
321 | 373 | | |
322 | 374 | | |
323 | 375 | | |
324 | 376 | | |
325 | 377 | | |
326 | 378 | | |
327 | 379 | | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
0 commit comments