How to unzip a big zip file containing one file and get the progress in bytes with swift?

前端 未结 4 2028
无人共我
无人共我 2020-12-30 03:35

I try to unzip a big zip file containing only one item (more than 100MB) and like to show the progress during unzipping.

I found solutions where the progress can be

4条回答
  •  孤独总比滥情好
    2020-12-30 04:06

    You can try this code :

        SSZipArchive.unzipFileAtPath(filePath, toDestination: self.destinationPath, progressHandler: { 
    (entry, zipInfo, readByte, totalByte) -> Void in
          //Create UIProgressView
          //Its an exemple, you can create it with the storyboard...
          var progressBar : UIProgressView?
          progressBar = UIProgressView(progressViewStyle: .Bar)
          progressBar?.center = view.center
          progressBar?.frame = self.view.center
          progressBar?.progress = 0.0
          progressBar?.trackTintColor = UIColor.lightGrayColor();
          progressBar?.tintColor = UIColor.redColor();
          self.view.addSubview(progressBar)
    
          //Asynchrone task                
          dispatch_async(dispatch_get_main_queue()) {
               println("readByte : \(readByte)")
               println("totalByte : \(totalByte)")                               
    
               //Change progress value
               progressBar?.setProgress(Float(readByte/totalByte), animated: true)
               //If progressView == 100% then hide it
               if readByte == totalByte {
                   progressBar?.hidden = true
               }
           }
    }, completionHandler: { (path, success, error) -> Void in
        if success {
            //SUCCESSFUL!!
        } else {
            println(error)
        }
    })
    

    I hope I have helped you!

    Ysee

提交回复
热议问题