Skip to content

LimeZip 压缩解压

  • UTS跨平台压缩解压插件,支持密码保护、进度回调。
  • 鸿蒙由于官方未提供加密和进度的API 暂时不支持密码和进度回调

安装

插件市场入口 导入,在页面引入,自定义基座

注意 本插件是付费,建议:
✅ 先试用后购买
✅ 完成安卓/iOS真机测试
✅ 试用测试满意后,慎重考虑后再购买

代码演示

压缩

支持加密、多路径
sourcePath: 路径支持文件或文件件
sourcePaths: 路径数组,可选,同样支持文件或文件夹 //鸿蒙next不支持
password: 设置密码,可选 //鸿蒙next不支持

js
import { zip, type ZipOptions } from '@/uni_modules/lime-zip'

zip({
	password: '444555',  // 可选加密密码 //鸿蒙next不支持
	sourcePath: '/static', // 支持文件/文件夹
	outputPath: '/storage/backup_${Date.now()}.zip', // 可选输出路径,不写默认则为缓存地址
	// sourcePath: '/static/logo.svg',
	// sourcePaths: ['/static/mp3/b.mp3', '/static/font/uni.ttf'],
	// sourcePaths: ['/static/mp3', '/static/font'],
	success(res) {
		console.log('zip res', res.tempFilePath)
	},
	fail(err) {
		console.log('err', err)
	},
	progress(p : number, t : number) {
		//鸿蒙next不支持
		console.log('进度', p)
		console.log('总数', t)
	}
} as ZipOptions)

解压

password: 解压包密码,如果有的话。没有不需要写 //鸿蒙next不支持 zipPath: 解压包路径

js
import { unzip, type UnZipOptions } from '@/uni_modules/lime-zip'
unzip({
	password: '444555', // 加密压缩包必填,若无密侧忽略 //鸿蒙next不支持
	zipPath: res.tempFilePath,
	outputPath: '/unpacked',    // 可选解压目录
	success(res) {
		console.log('unzip res', res)
	},
	fail(err) {
		console.log('unzip err', err)
	},
	progress(p : number, t : number) {
		//鸿蒙next不支持
		unprogress.value = Math.round((p / t) * 100)
	}
} as UnZipOptions)

UNIAPP

压缩

js
import { zip } from '@/uni_modules/lime-zip'

zip({
	password: '444555',  // 可选加密密码
	sourcePath: '/static', // 支持文件/文件夹
	 outputPath: '/storage/backup_${Date.now()}.zip', // 可选输出路径,不写默认则为缓存地址
	// sourcePath: '/static/logo.svg',
	// sourcePaths: ['/static/mp3/b.mp3', '/static/font/uni.ttf'],
	// sourcePaths: ['/static/mp3', '/static/font'],
	success(res) {
		console.log('zip res', res.tempFilePath)
	},
	fail(err) {
		console.log('err', err)
	},
	progress(p, t) {
		console.log('进度', p)
		console.log('总数', t)
	}
})

解压

password: 解压包密码,如果有的话。没有不需要写 //鸿蒙next不支持
zipPath: 解压包路径

js
import { unzip } from '@/uni_modules/lime-zip'
unzip({
	password: '444555', // 加密压缩包必填,若无密侧忽略  //鸿蒙next不支持
	zipPath: res.tempFilePath,
	outputPath: '/unpacked',    // 可选解压目录
	success(res) {
		console.log('unzip res', res)
	},
	fail(err) {
		console.log('unzip err', err)
	},
	progress(p , t ) {
		//鸿蒙next不支持
		unprogress.value = Math.round((p / t) * 100)
	}
})

查看示例

  • 导入后直接使用这个标签查看演示效果
html
<!-- // 代码位于 uni_modules/lime-zip/compoents/lime-zip -->
<lime-zip />

源代码

组件源码