【问题标题】:Unzip a downloaded file in swift5在swift5中解压下载的文件
【发布时间】:2022-09-30 19:23:57
【问题描述】:

纽布在这里。我想快速解压缩 .tar.gz 文件。我知道如何解压缩一个扩展名的文件。现在请告诉我如何解压缩这个文件。我是否需要执行两次解压缩或 swift 中有任何其他选项?

提前致谢!!

 AF.download(ref)
            .downloadProgress(queue: progressQueue) { progress in
            }
            .responseData { response in
                if let data = response.value {
   
                }
            }```


    标签: ios file unzip


    【解决方案1】:

    让组 = DispatchGroup()

        let folder = try! FileManager.default
            .url(for: .cachesDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
            .appendingPathComponent("SourceFiles")
        for (indexVal, ref) in arrayURL.enumerated() {
            
            let destination: DownloadRequest.Destination = { _, _ in
                    let fileURL = folder.appendingPathComponent(ref.lastPathComponent)
                    return (fileURL, [.createIntermediateDirectories])
                }
          print(destination)
            
            group.enter()
                        let progressQueue = DispatchQueue(label: "com.alamofire.progressQueue", qos: .utility)
            AF.download(ref, to: destination).downloadProgress(queue: progressQueue) { progress in
                                   print("Download Progress: \(progress.fractionCompleted)")
                
                DispatchQueue.main.async {
                    guard let cell = self.tableProgress.cellForRow(at: NSIndexPath.init(row: indexVal, section: 0) as IndexPath) as? ProgressCell else {
                        return // or fatalError() or whatever
                    }
                    cell.progressView.progress = Float(progress.fractionCompleted)
                }
            }.response { responseData in
                   switch responseData.result {
                   case .success(let url):
                       guard let url = url else { return }
                       print("fileurl", url)
                       do {
                           let unzipDirectory = try Zip.quickUnzipFile(url)
                           print("unzipDirectory", unzipDirectory)
                           
                       }
                       catch{
                           
                       }
                       group.leave()
    

    // self.urlLoad.append(url) case .failure(let error): print(error) } } } group.notify(queue: .main, execute: { // executed after all async calls in for loop finish print("done with all async calls") }) }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-12
      • 2021-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-15
      • 1970-01-01
      相关资源
      最近更新 更多