brendan-duncan / archive

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

Extract files from zip with broken names #249

Open starforce333 opened 1 year ago

starforce333 commented 1 year ago

``Trying to extract files and get errors. Files in archive has Cyrillic names.

If i use extractFileToDisk like this:

void unzip(File file) {
  extractFileToDisk(
      file.path,
      file.path.substring(0, file.path.lastIndexOf('\\') + 1) +
          p.basenameWithoutExtension(element.path));
}

I receive error "FormatException (FormatException: Unexpected extension byte (at offset 0))"

But when i use extractArchiveToDisk extracted files has broken names

void unzip(File file) {
  final bytes = File(file.path).readAsBytesSync();
  final archive = ZipDecoder().decodeBytes(bytes);
  extractArchiveToDisk(
      archive,
      file.path.substring(0, file.path.lastIndexOf('\\') + 1) +
          p.basenameWithoutExtension(file.path));
}

Extracted file has name Š­¨£ .xls, but original name of file is Книга.xls

Screenshot 2023-03-09 131859

archive.zip