【问题标题】:Compress string in Dart在 Dart 中压缩字符串
【发布时间】:2015-07-05 04:53:19
【问题描述】:

我用 Dart 创建了一个网页。用户以文本格式下载工作数据。 数据的容量将非常大,达到几兆字节。 当我用 ZIP 压缩文件时,它只有几千字节。

我找到了一种使用 Javascritp 库来压缩字符串的方法。

有没有办法在 Dart 中压缩字符串?

【问题讨论】:

标签: javascript dart


【解决方案1】:

您可以使用来自 pub 的 archive 包。它支持多种压缩算法和容器格式。它可以在浏览器和 DartVM 中运行,无需使用镜像。

收到二进制 zip 数据后(例如,通过 HttpRequest,请参阅 here how to get a continuous byte list),您可以使用 ZipDecoder 类打开和读取 zip 文件:

  Archive archive = new ZipDecoder().decodeBytes(bytes);

  for (ArchiveFile file in archive) {
    String filename = file.name;
    List<int> data = file.content;

    // Do something with the data from the file
  }

【讨论】:

  • 谢谢。容量减少了。
猜你喜欢
  • 1970-01-01
  • 2013-05-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-28
  • 1970-01-01
  • 2021-04-13
  • 1970-01-01
相关资源
最近更新 更多