HarmonyOS 鸿蒙Next 请问使用api10或者api11的,关于ZLib
HarmonyOS 鸿蒙Next 请问使用api10或者api11的,关于ZLib
@ohos.zlib,有没有扩展api,支持数据流的压缩和解压缩?
自己扩展C语言库这种造轮子行为有点不太想花时间做,官方有了就再等等,我不新个人开发者鸿蒙一直不开放api10或者11
解压
import zlib from '@ohos.zlib';
import base from '@ohos.base';
async function demo() {
let str = ‘hello world!’;
let arrayBufferIn = new ArrayBuffer(str.length);
let byteArray = new Uint8Array(arrayBufferIn);
for (let i = 0, j = str.length; i < j; i++) {
byteArray[i] = str.charCodeAt(i)
}
let arrayBufferOut = new ArrayBuffer(100);
let zip = zlib.createZipSync();
await zip.compress(arrayBufferOut, arrayBufferIn, 12).then((data) => {
console.info(‘compress success’);
}).catch((errData: base.BusinessError) => {
console.error(errData is errCode:${errData.code} message:${errData.message}
);
})
await zip.uncompress(arrayBufferIn, arrayBufferOut, 20).then((data) => {
console.info(‘uncompress success’);
}).catch((errData: base.BusinessError) => {
console.error(errData is errCode:${errData.code} message:${errData.message}
);
})
}
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>
api12终于等到官方原生流压缩和解压
import zlib from '@ohos.zlib';
import base from '@ohos.base';
let str = ‘hello world!’;
let arrayBufferIn = new ArrayBuffer(str.length);
let byteArray = new Uint8Array(arrayBufferIn);
for (let i = 0, j = str.length; i < j; i++) {
byteArray[i] = str.charCodeAt(i)
}
let arrayBufferOut = new ArrayBuffer(100);
let zip = zlib.createZipSync();
zip.compress(arrayBufferOut, arrayBufferOut, 20).then((data) => {
console.info(‘compress success:’);
}).catch((errData: base.BusinessError) => {
console.error(errData is errCode:${errData.code} message:${errData.message}
);
})
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>
https://ohos-rs.github.io/ecosystem/package/snappy.html
提供了一系列的NATIVE实现,有其他需求可以提PR 、issue
可以提issue给复现的流程看看。