Commit 09ac4fbc authored by Roy Marmelstein's avatar Roy Marmelstein

Quick unzip function

parent fc037ecd
...@@ -34,6 +34,18 @@ public class Zip { ...@@ -34,6 +34,18 @@ public class Zip {
public init () { 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 Unzip file
...@@ -107,7 +119,6 @@ public class Zip { ...@@ -107,7 +119,6 @@ public class Zip {
else { else {
try fileManager.createDirectoryAtPath(destination.path!, withIntermediateDirectories: true, attributes: directoryAttributes) try fileManager.createDirectoryAtPath(destination.path!, withIntermediateDirectories: true, attributes: directoryAttributes)
} }
if fileManager.fileExistsAtPath(fullPath) && !isDirectory && !overwrite { if fileManager.fileExistsAtPath(fullPath) && !isDirectory && !overwrite {
unzCloseCurrentFile(zip) unzCloseCurrentFile(zip)
ret = unzGoToNextFile(zip) ret = unzGoToNextFile(zip)
......
...@@ -18,7 +18,7 @@ class ViewController: UIViewController { ...@@ -18,7 +18,7 @@ class ViewController: UIViewController {
let fileAbsolutePath = NSBundle.mainBundle().pathForResource("master", ofType: "zip") let fileAbsolutePath = NSBundle.mainBundle().pathForResource("master", ofType: "zip")
let fileAbsoluteURL = NSURL(string: fileAbsolutePath!)! let fileAbsoluteURL = NSURL(string: fileAbsolutePath!)!
print(destinationPath) print(destinationPath)
try Zip().unzipFile(fileAbsoluteURL, destination: destinationPath, overwrite: true, password: nil) try Zip().unzipFile(fileAbsoluteURL)
} }
catch { catch {
print("oops") print("oops")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment