Working with zip files

208 views
Skip to first unread message

Andrew Skalkin

unread,
Oct 14, 2014, 5:31:19 PM10/14/14
to mi...@dartlang.org
I wonder if there are any plans to add native support for working with zip files in Dart? If not native, perhaps a library supported by the Dart team?

Zip files are ubiquitous, and there are hundreds of scenarios where it is beneficial to work with them on the client side (data uploading/dowloading, parsing of xlsx files, etc). It would be awesome if Dart provided a fast standard way for dealing with it.

Adam Stark

unread,
Oct 14, 2014, 6:00:31 PM10/14/14
to mi...@dartlang.org
It looks like there's a well supported package in pub: https://pub.dartlang.org/packages/archive


On Tue, Oct 14, 2014 at 2:31 PM, Andrew Skalkin <ska...@gmail.com> wrote:
I wonder if there are any plans to add native support for working with zip files in Dart? If not native, perhaps a library supported by the Dart team?

Zip files are ubiquitous, and there are hundreds of scenarios where it is beneficial to work with them on the client side (data uploading/dowloading, parsing of xlsx files, etc). It would be awesome if Dart provided a fast standard way for dealing with it.

--
For other discussions, see https://groups.google.com/a/dartlang.org/
 
For HOWTO questions, visit http://stackoverflow.com/tags/dart
 
To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.



--
Adam Stark

Brendan Duncan

unread,
Oct 24, 2014, 12:38:15 AM10/24/14
to mi...@dartlang.org
I wrote the 'archive' packge, https://pub.dartlang.org/packages/archive, which supports zip, tar, zlib, gzip, bzip2. There's no dependencies on io or html, so it can be used in both web and server applications. If you have any questions on using it, feel free to ask.

Andrew Skalkin

unread,
Oct 24, 2014, 12:47:58 AM10/24/14
to mi...@dartlang.org
Brendan, thanks a lot for developing this great package. I've been looking at its source code recently and I like it a lot; going to take it for a spin soon. I just wonder if you can share any thoughts on its performance, I'm sure you've compared it to native implementations?

Adam, thanks for pointing to it!

--

何宗憲

unread,
Nov 12, 2014, 5:30:42 AM11/12/14
to mi...@dartlang.org
Brendon,
   First of all, thank you for the package. I encounter problem using archive. I simply my implementation to the following code but it still hangs. Could you please let me know your suggestion?
-> Tracing result
   I trace the code and it seems being hung in line: 
          List<int> cData = arc[0].content;
   If I use the verify: true mode, the code would stuck inside decodeBytes() function call. 
-> Code is here

import 'dart:io' as IO;

import 'dart:async';

import 'package:http/http.dart' as http;

import 'package:archive/archive.dart';

import 'package:unittest/unittest.dart';

void main(){

  test("Test for Zip", (){

    Future future = http.get("http://data.fda.gov.tw/opendata/exportDataList.do?method=ExportData&InfoId=43&logType=3")

    .then((data){

      Archive arc = new ZipDecoder().decodeBytes(data.bodyBytes, verify:false);

      // Unzipped file has only one file. Save it as a raw json

      List<int> cData= arc[0].content;

      String fname = arc[0].name;

      new IO.File('data/' + fname)

                ..createSync(recursive: true)

                ..writeAsBytesSync(cData);

    });

    expect(future, completes);

  });

}


Andrew Skalkin於 2014年10月15日星期三UTC+8上午5時31分19秒寫道:

Brendan Duncan

unread,
Nov 12, 2014, 1:34:06 PM11/12/14
to mi...@dartlang.org
I just tried your example and it works for me. I did not do it as a unit test, so I expect the problem you're seeing is
expect(future, completes);
isn't a valid expectation to test for.

It extracts to a 91MB json file, decoding does take a little while (seemed to be about a minute or so on my macbook).

~Brendan

何宗憲

unread,
Nov 12, 2014, 2:30:28 PM11/12/14
to mi...@dartlang.org
Thanks for your prompt response. I think you are right. I found I made a mistake of assigning an inappropriate Future value to make my unittest fail. Attached is the working unittest.

  test("Test for Zip", (){

    Future future = http.get("http://data.fda.gov.tw/opendata/exportDataList.do?method=ExportData&InfoId=43&logType=3")

    .then((data){

      Archive arc = new ZipDecoder().decodeBytes(data.bodyBytes);

      // Unzipped file has only one file. Save it as a raw json

      List<int> cData= arc[0].content;

      String fname = arc[0].name;

      /*new IO.File('data/' + fname)

                ..createSync(recursive: true)

                ..writeAsBytesSync(cData);*/

      IO.IOSink sink = new IO.File('data/' + fname).openWrite();

      sink.write(UTF8.decode(cData));

      sink.close();

    }).then((_){

    });

    expect(future, completes);

  });


Brendan Duncan於 2014年11月13日星期四UTC+8上午2時34分06秒寫道:
Reply all
Reply to author
Forward
0 new messages