This package provides the necessary code to efficiently:
- Read the directory of ZIP files.
- Extract the contents from ZIP files.
- Recover ZIP files that are partially damaged / missing a central directory.
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();This package doesn't currently support the ZIP64 file format for large files (over 4GB)
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.
When reviewing/modifying the code in this package please consult the specification for the ZIP file format.