@nativescript/zip
NativeScript 中用于压缩和解压缩文件的简单实用类
npm i --save @nativescript/zip

@nativescript/zip

npm install @nativescript/zip

用法

压缩

查看 ZipOptions

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
});

进度

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({
function onZipProgress(percent: number) {
console.log(`unzip progress: ${percent}`);
directory: dest,
archive: zipPath,
onProgress: onZipProgress
});

解压缩

查看 UnzipOptions

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,
});

进度

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,
onProgress: onUnZipProgress,
});

function onUnZipProgress(percent: number) {
console.log(`unzip progress: ${percent}`);
}

许可证

Apache 许可证版本 2.0