在 Dart 中压缩字符串

Compress string in Dart

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

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

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

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

收到二进制 zip 数据后(例如通过 HttpRequest, see here how to get a continuous byte list) you can open and read the zip file using the ZipDecoder class:

  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
  }