npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cordova-ohos/cordova-plugin-zip

v3.1.0

Published

Cordova zip Plugin

Downloads

130

Readme

cordova-plugin-zip 压缩解压插件

一款轻量高效的 Cordova 压缩解压插件,基于 ZLib 库开发,支持 ZIP 格式文件的创建、解压及进度监听,适配 Android iOS、OHOS 三平台,为混合式移动应用提供便捷的文件压缩解压解决方案,适用于资源打包、文件传输优化等场景,本文档只介绍在OHOS系统中的应用。

功能特性

  • 压缩功能:支持单个文件、多个文件或整个目录的 ZIP 压缩,可自定义压缩级别

  • 解压功能:支持 ZIP 格式文件解压到指定目录,兼容加密 ZIP 文件(仅支持传统加密)

  • 进度监听:提供压缩/解压进度回调,实时返回处理进度百分比,便于展示进度条

  • 编码支持:支持 UTF-8 等多种编码格式,解决中文文件名乱码问题

  • 轻量高效:基于 ZLib 原生库开发,压缩解压速度快,资源占用低

  • 错误处理:完善的错误处理机制,返回详细错误信息便于问题定位

安装方法

确保已创建 Cordova 项目(若未创建,执行 cordova create zipDemo com.example.zip ZipDemo 创建),进入项目根目录后通过以下方式安装插件:

1. 基础安装(从 npm 仓库)

# 安装hcordova
npm install -g hcordova

# 安装稳定版插件
hcordova plugin add cordova-plugin-zip

2. 安装指定版本


# 安装 1.0.0 版本
hcordova plugin add [email protected] --platform ohos

3. 从 GitCode 安装开发版


hcordova plugin add https://gitcode.com/OpenHarmony-Cordova/cordova-plugin-zip.git --platform ohos

卸载方法

进入项目根目录,执行以下命令卸载插件:

# 全平台卸载
hcordova plugin remove cordova-plugin-zip

# 指定OHOS卸载
hcordova plugin remove cordova-plugin-zip --plarform ohos

核心 API

解压 ZIP 文件

将 ZIP 文件解压到指定目录。

function unzipProgressFun(progressEvent) {
    var progress = progressEvent.loaded / progressEvent.total * 100;
    document.getElementById("progress").innerHTML = "解压:"+progress+"%100";
}

/*
* path:解压沙箱路径
* zipFile:解压文件沙箱路径
*/
zip.unzip(path, zipFile, function(isOk){
    if(isOk == -1) {
        alert("解压失败");
    }
},unzipProgressFun)

使用示例

注意:下载解压文件


function downloadAndUnZip() {
    function unzipProgressFun(progressEvent) {
        var progress = progressEvent.loaded / progressEvent.total * 100;
        document.getElementById("progress").innerHTML = "解压:"+progress+"%100";
    }

    function successFun(fileEntry) {
        console.log("download complete: " + fileEntry.toURL());
        window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function(dirEntry) {
            zip.unzip(fileEntry.toURL(), dirEntry.toURL()+"zip", function(isOk){
                if(isOk == -1) {
                    alert("解压失败");
                }
            },unzipProgressFun)
        });
    }

    function failFun(error) {
        console.log("An error has occurred: Code = " + error.code);
        console.log("upload error source " + error.source);
        console.log("upload error target " + error.target);
        alert('下载失败。');
    }

    function progressFun(progressEvent) {
        var progress = progressEvent.loaded / progressEvent.total * 100;
        document.getElementById("progress").innerHTML = "下载:"+progress+"%100";
    }

    var uri = "https://www.chuzhitong.com/ceshi.zip";
    window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function(dirEntry) {
        var targetPath = dirEntry.toURL() + "ceshi.zip";
        var fileTransfer = new FileTransfer();
        fileTransfer.onprogress = progressFun;
        fileTransfer.download(
            uri,
            targetPath,
            successFun,
            failFun,
            false,
            {}
        );
    });
}

许可证

本插件采用 Apache License 2.0 开源许可证。

联系方式