-
-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unzipping in-memory archive #173
Comments
Hi Max, Sorry for the delayed reply. There are currently no convenience methods on |
A workaround I'm currently using is extracting each entry individually in an archive. The destination could be either on disk or in memory. This is also how zipping and unzipping an entire archive works internally in ZIP Foundation. |
Can u tell me how u did it? I struggle to unpack the password protected archive to memory. |
This is really awesome ... in-memory unzipping! I would expect I have to do something like this:
But that gives me an error: "'dataDescriptor' is inaccessible due to 'internal' protection level" How do I get the unzipped data for an entry? |
I solved it:
Awesome! |
@danio0701 Sorry for this really really late response! The way I did it (here in this semi-abandoned project) is mostly the same as how @Yourney did it. The only thing I want to mention is that, depending on whether you want the entire directory structure, or just the files, or any specific file, you can guard let archive = Archive(data: yourData, accessMode: .read) else { ... }
for entry in archive where entry.type == .file /* or .directory depending on your need */ {
do {
_ = try archive.extract(entry, skipCRC32: true, progress: nil) { data in
// do what you need with the data
// e.g. reassemble the directory structure here if you need it
}
} catch { ... }
} |
Thanks for the added tips! |
Hey I implemented my solution using this library https://github.com/marmelroy/Zip and my fully working solution is here marmelroy/Zip#269 the great thing is with this minizip swift wrapper you can unzip a password protected file now with this proposed solution you can do it also memory. Thanks |
Is your feature request related to a problem? Please describe.
It doesn't seem like there's a way to unzip an in-memory archive created with
Archive(data:)
initializer.Describe the solution you'd like
An extension function on
FileManager
that takes an instance ofArchive
as an argument and unzips the archive in a given directory.Describe alternatives you've considered
I've tried writing an in-memory archive to the filesystem first and then using the existing
unzipItem
extension function onFileManager
, but that has a performance hit due to the fact that this requires writing the archive itself to disk.Additional context
Writing the archive to disk is not needed in my case, it's held entirely in memory as it was donwloaded from network and there's no need to write the archive itself to disk, the app needs to write unzipped archive content directly to disk. The in-memory zip data is immediately discarded.
The text was updated successfully, but these errors were encountered: