HarmonyOS 如何使用gzip解压文件?

zip文件只能使用gzip解压,普通的zlib解压方式解不出来。有没有demo参考?

HarmonyOS
2025-01-10 08:55:06
1.0w浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Excelsior_abit

示例参考如下:

import { zlib } from '@kit.BasicServicesKit'
import { util } from '@kit.ArkTS'
import { common, Want } from '@kit.AbilityKit'

@Entry
@Component
struct TextInputExample {
  async readGzFile(inFile: string) {
    let gzip = zlib.createGZipSync();
    await gzip.gzopen(inFile, "rb");
    let endStatus = 0;
    do {
      let readBuf = new ArrayBuffer(4096);
      let len = await gzip.gzread(readBuf);
      console.info("gzread: " + len);
      const decoder = util.TextDecoder.create('utf-8').decodeWithStream(new Uint8Array(readBuf));
      console.info("content: " + decoder.toString())
      endStatus = await gzip.gzeof();
      console.info("endStatus: " + endStatus)
    } while (endStatus != 1)
  }

  build() {
    Column() {
      Button('tempgzip').onClick(() => {
        // 关闭自定义键盘
        this.readGzFile(getContext(this).filesDir+"/"+'xxx.zip')
      })
      Button("系统通知设置页").onClick(()=>{
        let context = getContext(this) as common.UIAbilityContext;
        let want: Want = {
          bundleName: 'com.huawei.hmos.settings',
          abilityName: 'com.huawei.hmos.settings.MainAbility',
          uri: "location_manager_settings",//消息通知传uri:systemui_notification_settings, 蓝牙传uri:bluetooth_entry, Wi-Fi传uri:wifi_entry,定位权限传uri:location_manager_settings
          parameters: {
            pushParams: {
              bundleName:"com.example.myapplication"
            } // 应用包名
          }
        };
        console.log("want",want)
        context.startAbility(want)
      }).margin(10)
    }
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
分享
微博
QQ
微信
回复
2025-01-10 12:37:04


相关问题
HarmonyOS 如何解压gzip格式文件
387浏览 • 1回复 待解决
HarmonyOS 如何解压gzip到某个文件夹下
401浏览 • 1回复 待解决
HarmonyOS gzip压缩和解压缩接口
1135浏览 • 1回复 待解决
HarmonyOS 如何解压GZIP压缩过的字符串
440浏览 • 1回复 待解决
HarmonyOS如何解压GZIP压缩过的字符串?
1243浏览 • 1回复 待解决
HarmonyOS 解压gzip格式压缩的数据流
431浏览 • 1回复 待解决
HarmonyOS gzip二进制流压缩和解压
1449浏览 • 1回复 待解决
HarmonyOS 无法解压文件
486浏览 • 1回复 待解决
HarmonyOS 代码如何解压zip文件
511浏览 • 1回复 待解决
网络请求:gzip压缩使用
803浏览 • 1回复 待解决
网络请求使用gzip压缩数据
2646浏览 • 1回复 待解决
HarmonyOS如何解压rawfile中的zip文件
767浏览 • 1回复 待解决
鸿蒙里如何通过代码解压zip文件
486浏览 • 0回复 待解决
实现文件解压缩和数据流解压
1885浏览 • 1回复 待解决