unzipping files with swift

I am downloading image files which are in the zip format to a folder in my app files folder. 
When the folder is opened the file is shown as .zip and when selected it unzips and creates a new file.  In my case it creates a jpg. leaving the zip file also.

My question is, how do I  unzip the file with swift since iOS  appears to have the capability?

Accepted Reply

The files I am downloading are single file .zip.

A single file zip archive still includes a zip structure. The Compression framework knows nothing about this zip structure. It can work with the compressed byte streams in this structure, but you’d have to parse them out the structure first. Hence my suggestion that you need to either write or acquire a library that understands the zip structure.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Replies

iOS does not have an API for manipulating zip archives (r. 22151959)-: If you need to do that, you’ll have to write or acquire a library for it.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • Thanks It's odd native IOS will decompress, but no algorithm for .zip in compression_algorithm of compression framework. must be a copyright issue?

Add a Comment

but no algorithm for .zip in compression_algorithm of Compression framework

You’re mixing up two things:

  • The Compression framework deals with compressed byte streams.

  • A zip archive is a high-level structure that holds a set of compressed byte streams.

Consider this:

% unzip -l -v QProcessDock.zip
Archive:  QProcessDock.zip
 Length   Method    Size  Cmpr … Name
--------  ------  ------- ---- … ----
       0  Stored        0   0% … QProcessDock.app/
……
  151744  Defl:N    54638  64% … QProcessDock.app/Contents/MacOS/QProcessDock
…

The zip archive contains many items, files and directories. Each item can use a different compression byte stream format. For example, the QProcessDock.app directory uses the Stored format, that is, it’s a byte-for-byte copy. In contrast, the app’s main executable use the Defl:N format, which is equivalent to COMPRESSION_ZLIB in the Compression framework.

So, Compression framework will deal with these compressed byte streams; what it can’t deal with is the higher-level structure of the zip archive.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • The files I am downloading are single file .zip. But haven't had any luck using the compression framework trying all types of compression_algorithm. I have found an aftermarket library to unzip for now, which unzips my downloads as a single file.

    These are us gov maps. They do come in zipped folders with many files, but I am parsing the folder on their site and downloading only the maps. This works good except they download as .zip and the user needs to select them to have ios unzip. I would rather be able to skip this step. Compression reports Fatal error: Error occurred during decoding: The operation couldn’t be completed. (Compression.FilterError error 1.). I haven't been able to find what error 1 is yet.

    Thanks

Add a Comment

The files I am downloading are single file .zip.

A single file zip archive still includes a zip structure. The Compression framework knows nothing about this zip structure. It can work with the compressed byte streams in this structure, but you’d have to parse them out the structure first. Hence my suggestion that you need to either write or acquire a library that understands the zip structure.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"