Clear Filters
Clear Filters

Unzip will not work on some archives

40 views (last 30 days)
When I run the unzip function, it will fail on certain archives. What really confuses me is that I can extract an archive's contents manually via the gui (right click an archive -> unzip).
Error message is simply "Invalid ZIP file:
C:\users\Desktop\myzipfile.zip"
The zip file is not invalid, and it is not corrupted
  4 Comments
Matthew Rademacher
Matthew Rademacher on 24 Apr 2023
@Walter Roberson, using your suggestions I've learned that my problem is that unzip fails while trying to extract entries created with the deflate64 method. (which lines up with the problem seen a decade ago here: Matlab fails to unzip large files - MATLAB Answers - MATLAB Central (mathworks.com)).
With that knowledge, do I have any options?

Sign in to comment.

Accepted Answer

chrisw23
chrisw23 on 12 Apr 2023
Edited: Walter Roberson on 14 Apr 2023
try to use .net Functionality (Windows OS assumed)
asm = NET.addAssembly("System.IO.Compression");
import System.IO.Compression.ZipFileExtensions.*
ZipFileExtensions.ExtractToFile(...
ZipFileExtensions.ExtractToDirectory(...
% search for system.io.compression.zipfileextensions.extracttodirectory to get the argument list
  11 Comments
Matthew Rademacher
Matthew Rademacher on 25 Apr 2023
The code I posted above will successfully create a java Deflate64InputStream object- but I am struggling to actually do anything with it. I am new to both java and File Input Streams, so please forgive my ignorance.
Not sure if this is relevant, but I can read the JavaFileInputStream byte-by-byte, it's only the Deflate64 inputstream that yeilds an error from the "read" method.
Matthew Rademacher
Matthew Rademacher on 26 Apr 2023
Edited: Matthew Rademacher on 26 Apr 2023
I am not a huge fan of this implementation at all but I do have a workaround. I have to install 7zip and execute the 7z.exe executable from command line using the "!" operator. Kind of stinky that you need 7zip installed but I got stuck on the java implementation and need something that works. Here zpath is the path where the 7z.exe file is located (C:\Program Files\7-Zip for me), Archive is the .zip archive compressed with deflate64, and targetpath is the path you want the file to be on.
cmdstring = sprintf('!"%s7z.exe" x %s -o%s -y',zpath,Archive,TargetPath)
eval(cmdstring)

Sign in to comment.

More Answers (0)

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!