brendan-duncan/archive

InputFileStream not close in extractFileToDisk

Closed this issue · 4 comments

czw299 commented

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.

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

czw299 commented

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();
}

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

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.