Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@nativescript/zip) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@nativescript/zip
A plugin to zip and unzip files.
Contents
Installation
npm install @nativescript/zipUse @nativescript/zip
Zip a folder
To zip a folder, call the zip() method on the Zip class, passing it a ZipOptions object.
async zip() {
let zipPath = path.join(knownFolders.temp().path, 'stuff.zip');
let dest = path.join(knownFolders.currentApp().path, '/assets');
const zipped = await Zip.zip({
directory: dest,
archive: zipPath,
}).then((value)=>{
console.log("zipped",value)
}).catch(err=>{
console.error(err)
});
}Get zip request progress
To get the zip request progress, set the onProgress property to a function to handle the progress event.
in ZipOptions object passed to the zip().
import { Zip } from '@nativescript/zip';
import { path, knownFolders } from '@nativescript/core';
let zipPath = path.join(knownFolders.temp().path, 'stuff.zip');
let dest = path.join(knownFolders.documents().path, '/assets');
Zip.zip({
directory: dest,
archive: zipPath,
onProgress: onZipProgress
});
function onZipProgress(percent: number) {
console.log(`unzip progress: ${percent}`);
}Unzip a folder
To unzip a folder, call the unzip() method on the Zip class, passing it a UnZipOptions object.
import { Zip } from '@nativescript/zip';
import { path, knownFolders } from '@nativescript/core';
let zipPath = path.join(knownFolders.temp().path, 'stuff.zip');
let dest = path.join(knownFolders.documents().path, '/assets');
Zip.unzip({
archive: zipPath,
directory: dest,
});Get unzip request progress
To get the unzip request progress, set the onProgress property to a function to handle the progress event.
import { Zip } from '@nativescript/zip';
import { path, knownFolders } from '@nativescript/core';
let zipPath = path.join(knownFolders.temp().path, 'stuff.zip');
let dest = path.join(knownFolders.documents().path, '/assets');
async unzip(){
const unzipped = await Zip.unzip({
archive: zipPath,
directory: dest,
onProgress: onUnZipProgress,
});
}
function onUnZipProgress(percent: number) {
console.log(`unzip progress: ${percent}`);
}API
Zip class
debugEnabled
Zip.debugEnabled = truezip()
Zip.zip(options).then((zipped: string) => {
}).catch((err) => {
})Zips the folder at the path specified in the directory property of the options parameter. It saves the zipped folder at the path set via archive property. The options object has the following properties:
ZipOptions interface
| Property | Type |
|---|---|
directory |
string |
archive |
string |
onProgress |
(progress: number) => void |
keepParent |
boolean |
password |
string |
unzip()
Zip.unzip(options).then((unZipped: any) => {
}).catch((err) => {
})Extracts all the files from the zip file specified in the archive property of the options parameter. The extracted files are stored at the path specified via the directory property. The options object has the following properties:
UnZipOptions interface
| Property | Type |
|---|---|
directory |
string |
archive |
string |
onProgress |
(progress: number) => void |
overwrite |
boolean |
password |
string |
License
Apache License Version 2.0