0.0.4 • Published 4 years ago

zip2 v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Welcome to zip2 👋

Version License: MIT

jszip based library that works on both node.js, browser and other cross platform.

Good compatibility with CapacitorJS via plugin capacitor-fs

Installation

yarn add zip2

Usage

Zip2.zip(options)

import fs from "fs"
import { zip } from "zip2"

await zip({
   fs,
   path: "folder-zip",
   filepaths: ["."],
   filter: (filepath: string) => filepath.startsWith("dist/") === false,
   onProgress: (event) => console.log(event),
   return: "folder-zip.zip"
})

console.log("Zipped done")

Options object:

ParamType = defaultDescription
fsLikeFsAn object that has the same functions as the fs module. Example capacitor-fs
pathstringThe parent folder contains files and subfolders that need zip compression.
filepathsstring[] = "."The files and folders that need zip compression will be listed here. If you want to select all use ["."], if you want to unzip a certain file or folder use ["!.git/"].
filter(filepath) => boolean = () => truefunction to filter files. Note this function has lower priority than options.filepaths
onProgress(event)? => void | PromiseThis function will be called every time a file or directory is added to the zip. View type object event
returnfalse | string?zip2 will return in any fashion. If options.return = false Zip2.zip() will return a Promise<ArrayBuffer>, if it is string Zip2.zip() will return a Promise<void> and save the zip file to options.return

Important note options.filepaths filters absolute paths. If you want to select a folder, you must have a / after it, otherwise Zip2 will understand that you want to select the file.

Zip2.unzip(options)

import fs from "fs"
import { unzip } from "unzip"

await unzip({
   fs,
   extractTo: "folder-extract-zip",
   filepaths: ["."],
   filter: (filepath: string) => filepath.startsWith("dist/") === false,
   onProgress: (event) => console.log(event),
   path: "folder-zip.zip"
})

Options object:

ParamType = defaultDescription
fsLikeFsAn object that has the same functions as the fs module. Example capacitor-fs
extractTostringUnzipped folder to
filepathsstring[] = "."The files and folders that need zip compression will be listed here. If you want to select all use ["."], if you want to unzip a certain file or folder use ["!.git/"].
filter(filepath) => boolean = () => truefunction to filter files. Note this function has lower priority than options.filepaths
onProgress(event)? => void | PromiseThis function will be called every time a file or directory is added to the zip. View type object event
dataArrayBuffer | Uint8Array?Buffer of file zip. Required this option or options.path
pathstring?Path to zip file. Required this option or options.data

Important note options.filepaths filters absolute paths. If you want to select a folder, you must have a / after it, otherwise Zip2 will understand that you want to select the file.

License

MIT (c) 2021 Tachibana Shin

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago