From 09ac4fbc0106de29bee624f92c79c82c6c2f8884 Mon Sep 17 00:00:00 2001 From: Roy Marmelstein Date: Thu, 14 Jan 2016 00:30:25 +0100 Subject: [PATCH] Quick unzip function --- Zip/Zip.swift | 13 ++++++++++++- examples/Sample/Sample/ViewController.swift | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Zip/Zip.swift b/Zip/Zip.swift index c4e5fc9..3ace7ab 100644 --- a/Zip/Zip.swift +++ b/Zip/Zip.swift @@ -34,6 +34,18 @@ public class Zip { public init () { } + /** + Quick unzip file. Unzips to the app's documents folder. + + - parameter path: Path of zipped file. NSURL. + + - throws: Error if unzipping fails or if fail is not found. Can be printed with a description variable. + */ + public func unzipFile(path: NSURL) throws { + let documentsUrl = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL + try self.unzipFile(path, destination: documentsUrl, overwrite: true, password: nil) + } + /** Unzip file @@ -107,7 +119,6 @@ public class Zip { else { try fileManager.createDirectoryAtPath(destination.path!, withIntermediateDirectories: true, attributes: directoryAttributes) } - if fileManager.fileExistsAtPath(fullPath) && !isDirectory && !overwrite { unzCloseCurrentFile(zip) ret = unzGoToNextFile(zip) diff --git a/examples/Sample/Sample/ViewController.swift b/examples/Sample/Sample/ViewController.swift index 1d47c02..ae3661a 100644 --- a/examples/Sample/Sample/ViewController.swift +++ b/examples/Sample/Sample/ViewController.swift @@ -18,7 +18,7 @@ class ViewController: UIViewController { let fileAbsolutePath = NSBundle.mainBundle().pathForResource("master", ofType: "zip") let fileAbsoluteURL = NSURL(string: fileAbsolutePath!)! print(destinationPath) - try Zip().unzipFile(fileAbsoluteURL, destination: destinationPath, overwrite: true, password: nil) + try Zip().unzipFile(fileAbsoluteURL) } catch { print("oops") -- 2.26.2