HarmonyOS 使用pako包进行gzip压缩解压缩的时候,解压缩后的数据比原数据少了10个字符 -

压缩:pako.gzip(rowData, { level: 9 })

解压缩:pako.ungzip(res, { to: ‘string’ })

其中rowData为base64 string,res为压缩后的Uint8Array数据。

HarmonyOS
1天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
Excelsior_abit

参考示例:

import { buffer, util } from '@kit.ArkTS';
import pako from 'pako'

@Entry
@Component
struct Index {
  build() {
    Column() {
      Button("截图")
        .onClick(() => {
          let s = '123456789101111111111'
          let u = new Uint8Array(buffer.from(s, 'utf-8').buffer);
          // let rowData = new util.Base64Helper().encodeToStringSync(u)
          let rowData =
            'FAAAADAwMDIwMDAyMDI0MDUyODAwMDAw+xrWAFRRUlJWT1BKTmZpZmRXVF1eX1xfXlpjaGJmY2ZoZmZoa25nbHFua29rb25lZmhpZmpdV1pfXmJgaXB0hX+Qp6+3wMLJz9HQ0djWn2pikLS5rn9lVZnIxsLCvr27uLq5ubm3srKvq6qnpaWoqKiooZuThnJsZFVRUmJgYVldYl5UTUVIRz5BPUJOVlZXYFlmf3BST1leX2piaW5uaXFveH6CipCRlpOVmZibnZqZm52nq6icnJubnJ2eoaqoq6urq6qqqaepqKqvr6+wsa+vr6ysra+rqaiqrq+ws7Szsquus7W4srS0tbOzs7SztLS0trSyr7S0srS0s7Kxs7W1tLWztbS1t7a2s7SztbW0tbi5tbe3t7a2uLe2tLe4uLe4ubq5uri5uLi2t7i4tbW3uLe3t7e4ure5uLi5uLm5ubm5ubi5uLq6u7u5t7m7uru9u7y7vby7u7u7u7y9u7y9vby7u727vL2+vL2+vby/vr29vby+v7+9vb2+vry9vr2+v76+vr2+vr27vL67uLa2tra2tra3t7a1tbe3uLW2tbe3uLe4t7S0uLi3tbW2uLi3tre3ubi4t7m3t7e4uLi4ubq6ubq4urm5ubm5u7i5ubm5ubu6ubm6ubm5uLq8vLq7ubq0rrW4t7G0ubq6u7y7vb6+vL68u7u5u7y9vr2+vLu9vby9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1tba2tbS0tbW1t7S3tLW0t7e3trW2t7i4uLm2t7m4t7a2uLe4ube3t7m4uLi4ubi5uri4ubi3t7i4t7e4ubq4ubq6u7y6u7u6urq6u7y8u7i7vL28vb28u7u8uru6ury9vLy8vr29vb29vb29vr69vb68vL29vb2+vb6+vr69v7++wL++vr6/v76+vLu9u7y5uLe5uLi2t7W2tre3t7e2tra1t7e2tbW2t7e4tri3t7e4uLi5ubi4uLm4uLq4ubi5ubq4uLm5uru6ubm6urq7ubi6urq7urq5ubKosbm3s7W5u7u7u7u7vLy7vLu9vL29vru8vLu7u7q6ury7u7y7u7y8vLy7vL68vL29vLy8vLy8vLy9vby8vr29vLu9v8C/vr+/vr6+vr2+vr29vL28vLy5uLi1s7OzrKWlpKSkrLCztLW2tba5urm4ubi5urm6urq7uru7uru5ury/wMPCwL6+v7+/v7+/v7+/wL/Av76/wMDBwElKT1FPUVFOVmBmZGhiXF1bXl1bYGJiY2JhYmVlY2ZmZ2ppbG1ubm1wbXBsbW5va2piZGJjYlpgXVddYWRmc36GkJ+yu7m/ydLU1ti+c2Nopbixim9ecb'
          console.log('rowData    ' + rowData);

          const res: string | Uint8Array | undefined = pako.gzip(rowData, { level: 9 });
          console.log('res' + res);

          let ss: string | Uint8Array | undefined = pako.ungzip(res, { to: 'string' })
          console.log('ss' + ss)

        }).margin(10)
    }
    .width('100%')
    .height('100%')
    .alignItems(HorizontalAlign.Center)
  }
}
分享
微博
QQ
微信
回复
1天前
相关问题
实现文件解压缩数据解压缩
1526浏览 • 1回复 待解决
HarmonyOS gzip压缩解压缩接口
601浏览 • 1回复 待解决
HarmonyOS gzip二进制流压缩解压缩
855浏览 • 1回复 待解决
HarmonyOS ZIP文件加密压缩解压缩
836浏览 • 1回复 待解决
网络请求使用gzip压缩数据
2166浏览 • 1回复 待解决
如何解压有密码压缩
1793浏览 • 0回复 待解决
网络请求:gzip压缩使用
432浏览 • 1回复 待解决
HarmonyOS 压缩
32浏览 • 1回复 待解决