diff --git a/Zip/Zip.swift b/Zip/Zip.swift index c4e5fc9933a4b9ab866aa1790aa989eab8ac6d35..3ace7ab253309bf9f39581eb399ae309706db21a 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 1d47c0293993fe92aa40df93f8e6a46a06f1d23d..ae3661a29e2e3dab64d654e078500d8f9528b21e 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")