Remote access to files inside a ZIP file for macOS, iOS and watchOS.
ZipPinch
is an extension for URLSession
to work with zip files remotely. It reads the contents of a zip file without downloading it itself and decompresses the desired files.
Imagine that you need remote access to several files (different kinds of assets: pictures, fonts, etc.). And these files can be changed and added to. Perhaps these files are grouped, for example, by locale and your app needs assets for a particular locale. In a good way you need a server solution that returns some JSON with a description of available resources. For example, you can use any PaaS, but ZipPinch
offers a much simpler solution.
It makes a request to a remote ZIP archive and returns its structure with the file size and date of file modification. Free hosting for your zip files is not hard to find. Files in an uncompressed archive will essentially be downloaded as is and no time will be spent on unzipping.
Screenshots from the Demo app: Hubble
File
⟩ Add Packages...
Add Package
https://github.com/buh/ZipPinch.git
Add Package
URLSession
. Then make a request for the contents via a direct URL
to your ZIP file.let urlSession = URLSession(configuration: .default)
let entries = try await urlSession.zipEntries(from: url)
[!NOTE]
You can also add aURLSessionTaskDelegate
or use a customisedURLRequest
.
let data = try await urlSession.zipEntryData(entry, from: url)
Check out the Hubble demo app to view selected images from the archive taken by The Hubble Space Telescope.
To download with showing the progress, a ZIPProgress
object must be specified:
let data = try await urlSession.zipEntryData(entry, from: url, progress: .init() { progressValue in
Task { @MainActor in
self.progress = progressValue
}
})
let entries = try await urlSession.zipEntries(from: url)
let rootFolder = entries.rootFolder()
// folderData: [(entry: ZIPEntry, data: Data)]
let folderData = try await urlSession.zipFolderData(folder, from: url)
// folderData: [(entry: ZIPEntry, data: Data)]
let folderData = try await urlSession.zipFolderData(folder, from: url, progress: .init() { progressValue in
Task { @MainActor in
self.progress = progressValue
}
})
URLRequest
URLSessionTaskDelegate
You can buy me a coffee here ☕️
ZipPinch
is available under the MIT license