0.1.2 • Published 5 years ago
@szydlovski/zip v0.1.2
zip
Convenience functions for JSZip.
Usage
npm install @szydlovski/zipimport { decodeZipFile, encodeZipFile } from '@szydlovski/zip';
import { promises as fs } from 'fs';
(async () => {
const file = await fs.promises.readFile('path/to/archive.zip');
const data = await decodeZipFile(file);
const newFile = await encodeZipFile(data);
})();API
decodeZipFile(file, options = {})
Decodes a zip file using JSZip and returns a flat plain object containing key value pairs corresponding to each file in the archive, i.e.:
{
'a text file.txt': UInt8Array[...],
'path/to/folder/anotherfile.json': UInt8Array[...],
'path/to/folder/image.jpg': UInt8Array[...]
}Options:
- format -
string- the format to return file data in, defaults touint8array. Accepts formats supported by JSZip:base64,text,binarystring,array,uint8array,arraybuffer,blob,nodebuffer. - includeDirs -
boolean- whether to include intermediate & empty folders in the returned object, defaults tofalse. If true, the entries of folders will be set tonull, otherwise they will be omitted.
encodeZipFile(contents, options = {})
Encodes a zip file using JSZip and returns the resulting data. Accepts objects containing key value pairs corresponding to files and folders, just like the object returned by decodeZipFile.
Options:
- format -
string- the format to return file data in, defaults touint8array. Accepts formats supported by JSZip:base64,text,binarystring,array,uint8array,arraybuffer,blob,nodebuffer.