разархивирование 20-мегабайтного файла с помощью SSZipArchive не работает, но файл с несколькими килобайтами проходит - PullRequest
0 голосов
/ 06 июня 2019

Я распаковываю файлы с помощью SSZipArchive, но проблема в том, что когда размер файла составляет всего несколько килобайт, он успешно распаковывается, а когда размер файла составляет несколько мегабайт, он не распаковывается. это метод загрузки и распаковки файла:

func downloaddZip(zipUrl:URL)->Void{
            do {
                let applicationSupportFolderURL = try FileManager.default.url(for: .applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
                let folder = applicationSupportFolderURL.appendingPathComponent("Librelio/data/parution", isDirectory: true)

                print("[ERR]: Folder location: \(folder.path)")
                if !FileManager.default.fileExists(atPath: folder.path) {
                    try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true, attributes: nil)
                }
                let documentsUrl = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
                // your destination file url
                let detination = folder.appendingPathComponent(zipUrl.lastPathComponent)

                  print("destination " + detination.absoluteString)
                // check if it exists before downloading it

                if FileManager().fileExists(atPath: detination.absoluteString) {
                    print("The file already exists at path")
                    let result = SSZipArchive.unzipFile(atPath: detination.path, toDestination: folder.path)
                    print("namaste reuslat" + result.description)

                } else {


                    URLSession.shared.downloadTask(with: zipUrl, completionHandler: { (location, response, error) in
                        // after downloading your data you need to save it to your destination url
                        guard
                            let httpURLResponse = response as? HTTPURLResponse, httpURLResponse.statusCode == 200,
                            let location = location, error == nil
                            else { return }
                        do {
                            try FileManager.default.moveItem(at: location, to: detination)
                            print("file saved")
                            do{
                                print("namaste detination " + detination.path)
                              //  let file = try Zip.quickUnzipFile(location)

                                 let result = SSZipArchive.unzipFile(atPath: detination.path, toDestination: folder.path)
                                print("namaste reuslat" + result.description)


                            }catch {
                                print("Error: \(error.localizedDescription)")
                            }


                        } catch {
                            print("error while downloading")
                            print(error)
                        }
                    }).resume()
                }
            } catch {
                print("error downloading url")

                print(error) }                
        }

проходит для файла с путем: "https://github.com/VivekVithlani/QRCodeReader/archive/master.zip", но не для файла с этим путем: https://files.slack.com/files-pri/TFESL155M-FK3PE60GZ/download/kiosque.zip

...