brendan-duncan / archive

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

InputFileStream not close in extractFileToDisk #263

Closed czw299 closed 12 months ago

czw299 commented 1 year ago

When I use extractFileToDisk on Windows, the zip file could not be delete until exit the app. image It seem that a InputFileStream was fogot to close: image Could you fix it? Thanks. Sorry for my bad English.

ElHaban3ro commented 1 year ago

I also have this same problem and I can't find how to fix it :( Were you able to fix it?

czw299 commented 1 year ago

I also have this same problem and I can't find how to fix it :( Were you able to fix it?

I just wrote my own imitation of the original function, and close all InputFileStream, and it worked fine. But this is a simplified version that removes some of the original features, such as password support, which is enough for me.

Future<void> extractFileToDisk2(String inputPath, String outputPath) async {
  var archivePath = inputPath;
  final input = InputFileStream(archivePath);
  Archive archive = ZipDecoder().decodeBuffer(input);

  for (final file in archive.files) {
    final filePath = p.join(outputPath, p.normalize(file.name));

    if (!isWithinOutputPath(outputPath, filePath)) {
      continue;
    }

    if (!file.isFile && !file.isSymbolicLink) {
      Directory(filePath).createSync(recursive: true);
      continue;
    }

    if (file.isSymbolicLink) {
      final link = Link(filePath);
      await link.create(p.normalize(file.nameOfLinkedFile), recursive: true);
    } else {
      final output = File(filePath);
      final f = await output.create(recursive: true);
      final fp = await f.open(mode: FileMode.write);
      final bytes = file.content as List<int>;
      await fp.writeFrom(bytes);
      file.clear();
      await fp.close();
    }
  }

  await archive.clear();
  await input.close();
}
brendan-duncan commented 1 year ago

Sorry for the long delay, life has been very busy lately. I pushed an update to this on git. I have some other things in this library I've been neglecting lately I wanted to try to get to before pushing a version update.

czw299 commented 1 year ago

Sorry for the long delay, life has been very busy lately. I pushed an update to this on git. I have some other things in this library I've been neglecting lately I wanted to try to get to before pushing a version update.

😄It doesn't matter. Thanks a lot. Have a nice day.