2015-07-05 59 views
3

我用Dart創建了一個網頁。用戶以文本格式下載工作數據。 數據的容量將會非常大,爲數兆字節。 這是下降到幾千字節當我在ZIP壓縮文件。在Dart中壓縮字符串

我找到了一種通過使用Javascritp庫來壓縮字符串的方法。

有沒有辦法在Dart中壓縮字符串?

+0

是的,有:https://github.com/ roberthartung/zip.dart – Robert

回答

1

您可以使用酒吧的archive包。它支持多種壓縮算法和容器格式。它可以在瀏覽器和DartVM中使用,無需使用鏡像。

您在收到二進制壓縮數據後(通過HttpRequest例如,見here how to get a continuous byte list),您可以使用ZipDecoder類打開和讀取壓縮文件:

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 
    } 
+0

謝謝。容量減少了。 – okamoto