Skip to content

Commit

Permalink
Download zip entries data
Browse files Browse the repository at this point in the history
  • Loading branch information
buh committed Oct 11, 2023
1 parent 56f7faf commit 22a2acc
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion Sources/ZipPinch/URLSession+ZIPFolder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,43 @@ public extension URLSession {
delegate: URLSessionTaskDelegate? = nil,
progress: ZIPProgress? = nil,
decompressor: @escaping (_ compressedData: NSData) throws -> NSData = { try $0.decompressed(using: .zlib) }
) async throws -> [(ZIPEntry, Data)] {
try await zipEntriesData(
folder.allEntries(),
for: request,
delegate: delegate,
progress: progress,
decompressor: decompressor
)
}

/// Retrieves the contents of the ZIP entries.
func zipEntriesData(
_ entries: [ZIPEntry],
from url: URL,
cachePolicy: URLRequest.CachePolicy = .reloadRevalidatingCacheData,
delegate: URLSessionTaskDelegate? = nil,
progress: ZIPProgress? = nil,
decompressor: @escaping (_ compressedData: NSData) throws -> NSData = { try $0.decompressed(using: .zlib) }
) async throws -> [(ZIPEntry, Data)] {
try await zipEntriesData(
entries,
for: URLRequest(url: url, cachePolicy: cachePolicy),
delegate: delegate,
progress: progress,
decompressor: decompressor
)
}

/// Retrieves the contents of the ZIP entries.
func zipEntriesData(
_ entries: [ZIPEntry],
for request: URLRequest,
delegate: URLSessionTaskDelegate? = nil,
progress: ZIPProgress? = nil,
decompressor: @escaping (_ compressedData: NSData) throws -> NSData = { try $0.decompressed(using: .zlib) }
) async throws -> [(ZIPEntry, Data)] {
try await withThrowingTaskGroup(of: (ZIPEntry, Data).self) { taskGroup in
let entries = folder.allEntries()
let overallProgress = OverallProgress(count: Double(entries.count))

for entry in entries {
Expand Down

0 comments on commit 22a2acc

Please sign in to comment.