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?
Answered by DTS Engineer in 695770022

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"

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"

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"

Accepted Answer

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"

unzipping files with swift
 
 
Q