Skip to content

Repository files navigation

@merlin4/zip

This package provides the necessary code to efficiently:

  1. Read the directory of ZIP files.
  2. Extract the contents from ZIP files.
  3. Recover ZIP files that are partially damaged / missing a central directory.

Usage: Read directory and unzip all files

import{readZipDirectory,unzipToFile}from"@merlin4/zip";import{FileHandle,open}from"node:fs/promises";import{resolveaspathResolve}from"node:path";asyncfunctionmain(){letfileHandle: FileHandle|undefined;try{constzipPath=pathResolve("./data/example.zip");constoutDir=pathResolve("./temp/example");// open zip filefileHandle=awaitopen(zipPath,"r");// read the zip's table of contentsconstdirectory=awaitreadZipDirectory(fileHandle);// unzip all of the filesfor(constentryofdirectory.entries){constoutPath=pathResolve(outDir,entry.fileName);awaitunzipToFile(fileHandle,entry,outPath);}}finally{if(fileHandle){awaitfileHandle.close();}}}main();

ZIP64

This package doesn't currently support the ZIP64 file format for large files (over 4GB)

Performance & Streaming

CPU & Memory performance are both very important to this package. As such, a significant effort has been made to stream the data and efficiently use buffers to reduce the memory needed to process ZIP files.

As such, the code leverages low-level c-style techniques of reducing memory usage and reusing buffers where possible.

ZIP File Format

When reviewing/modifying the code in this package please consult the specification for the ZIP file format.

  1. https://en.wikipedia.org/wiki/ZIP_(file_format)
  2. https://users.cs.jmu.edu/buchhofp/forensics/formats/pkzip.html
  3. https://www.loc.gov/preservation/digital/formats/fdd/fdd000354.shtml
  4. https://pkware.cachefly.net/webdocs/APPNOTE/APPNOTE-6.3.9.TXT

About

Package to efficiently read the contents of zip files

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Used by

Contributors

Languages