更新记录
0.0.2(2025-05-02)
- feat 增加
decompressGzipSync
同步方法
0.0.1(2025-05-01)
- init
平台兼容性
Vue2 | Vue3 |
---|---|
√ | √ |
App | 快应用 | 微信小程序 | 支付宝小程序 | 百度小程序 | 字节小程序 | QQ小程序 |
---|---|---|---|---|---|---|
Android:4.4,iOS:9,HarmonyNext:支持 | × | √ | × | × | × | × |
钉钉小程序 | 快手小程序 | 飞书小程序 | 京东小程序 | 鸿蒙元服务 |
---|---|---|---|---|
× | × | × | × | × |
H5-Safari | Android Browser | 微信浏览器(Android) | QQ浏览器(Android) | Chrome | IE | Edge | Firefox | PC-Safari |
---|---|---|---|---|---|---|---|---|
√ | √ | √ | √ | √ | √ | √ | √ | √ |
lime-gzip GZip 数据流解压
安装
插件市场导入,安卓,ios需要自定义基座,鸿蒙next和web只能源码使用
引入
// uniapp不需要强制类型 所以不需要引入 UnGZipOptions
import { decompressGzip, decompressGzipSync, type UnGZipOptions } from '@/uni_modules/lime-gzip'
API 详解
decompressGzip 解压方法
function decompressGzip(options: UnGZipOptions): void
// 同步方法
function decompressGzipSync(options: UnGZipOptions): UnGZipSuccess|null
参数说明:
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
asText | boolean |
否 | 控制返回格式: - true: 解码为字符串 - false: 返回Uint8Array(默认) |
其他参数 | 同gzip方法参数说明 |
返回结果(UnGZipSuccess):
interface UnGZipSuccess {
data?: Uint8Array | string // 根据asText参数决定类型
outputPath?: string
originalSize: number // 解压后数据大小
compressedSize: number // 压缩前数据大小
}
使用示例
const compressedData = new Uint8Array([...]); // GZIP压缩数据
// 返回 Uint8Array
decompressGzip({
input: compressedData,
success: (res) => {
console.log('Decompressed data:', res.data);
console.log('Original size:', res.originalSize);
console.log('Compressed size:', res.compressedSize);
}
} as UnGZipOptions); // uniapp不需要强制类型 所以不需要 as UnGZipOptions
// 返回字符串
decompressGzip({
input: compressedData,
asText: true,
success: (res) => {
console.log('Decompressed text:', res.data);
}
} as UnGZipOptions); // uniapp不需要强制类型 所以不需要 as UnGZipOptions
compressToGzip 压缩方法
该方法未实现
function compressToGzip(options: GZipOptions): void
参数说明:
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
input | Uint8Array|string |
是 | 支持三种输入形式: - 二进制数据(Uint8Array) - 原始字符串 - 文件路径字符串(未实现) |
isFile | boolean |
否 | 文件操作模式开关(默认false)未实现 |
outputPath | string |
条件必填 | isFile=true时需指定输出路径 未实现 |
success | function |
否 | 操作成功回调,返回结构见GZipSuccess |
fail | function |
否 | 操作失败回调,返回结构见GZipFail |
complete | function |
否 | 最终回调,接收成功/失败结果 |
返回结果(GZipSuccess):
interface GZipSuccess {
data?: Uint8Array | string // 非文件模式返回压缩数据
outputPath?: string // 文件模式返回存储路径
originalSize: number // 原始数据字节数
compressedSize: number // 压缩后字节数
}
错误处理
错误码规范
type GZipErrorCode =
9010001 | // 输入数据无效
9010002 | // 文件读取失败
9010003 | // 文件写入失败
9010004 | // 解压过程失败
9010005 | // 非法的GZIP格式
9010006 | // CRC校验失败
9099999 // 未知错误
错误对象结构
interface GZipFail {
errCode: GZipErrorCode
errMsg: string
// 继承自IUniError的其他标准字段...
}