brendan-duncan / archive

Dart library to encode and decode various archive and compression formats, such as Zip, Tar, GZip, ZLib, and BZip2.
MIT License
411 stars 141 forks source link

ZipFileEncoder.addFile() must support File but not String paths. #215

Open PavelTurk opened 2 years ago

PavelTurk commented 2 years ago

Consider the following code:

    IO.File file = MemoryFileSystem().file('temp.html')
      ..writeAsString("123", mode: IO.FileMode.writeOnly, flush: true);

    file.readAsString().then((value) => print(value));

    var encoder = ZipFileEncoder();
    encoder.create(path + "/"+'temp.zip');
    encoder.addFile(file);
    encoder.close();

This code doesn't work:

E/flutter ( 5096): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: FileSystemException: Cannot open file, path = 'temp.html' (OS Error: No such file or directory, errno = 2)
E/flutter ( 5096): #0      _File.throwIfError (dart:io/file_impl.dart:635:7)
E/flutter ( 5096): #1      _File.openSync (dart:io/file_impl.dart:479:5)
E/flutter ( 5096): #2      new FileHandle (package:archive/src/io/input_file_stream.dart:16:25)
E/flutter ( 5096): #3      new InputFileStream (package:archive/src/io/input_file_stream.dart:81:17)
E/flutter ( 5096): #4      ZipFileEncoder.addFile (package:archive/src/io/zip_file_encoder.dart:67:22)

The problem is that in addFile the first line is var fileStream = InputFileStream(file.path);. So, as we see File type is not supported. So, I suggest to add such support.