Search code examples
swiftmacoszipzipfoundation

Using ZIPFoundation without URL


In my MacOS app I am downloading an encrypted .zip file to the disk. I decrypt this file and keep the decrypted version in memory in the Data type. For security reasons the decrypted .zip will only be kept in memory.

I can successfully use ZIPFoundation's Closure based reading to extract the file contents in memory, but only by using an URL pointing to the (decrypted) .zip on disk:

guard let archive = Archive(url: url!, accessMode: .read) else { return }

Is there any way I can use the library with data only existing in memory? If not, can you point me towards a library that can handle this? I have already tried DataCompression, but I couldn't make it work.


Solution

  • There's a (non-merged) Pull Request open that adds in-memory processing of ZIP archives to ZIP Foundation.
    Sadly there are still some unresolved issues with in-memory writing of archives. The reading part is using fmemopen and should already work.
    While the PR is not finished yet, you can have a look here: https://github.com/weichsel/ZIPFoundation/pull/78/