From a88d3d3580520c0a0af20c9ce1c252308532de9f Mon Sep 17 00:00:00 2001 From: Roy Marmelstein Date: Wed, 13 Jan 2016 22:08:12 +0100 Subject: [PATCH] Minor clean up --- Zip/Zip.swift | 14 +++++++------- examples/Sample/Sample/ViewController.swift | 5 +++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Zip/Zip.swift b/Zip/Zip.swift index 4ee7324..2fb3561 100644 --- a/Zip/Zip.swift +++ b/Zip/Zip.swift @@ -26,13 +26,13 @@ public class Zip { public init () {} - public func unzipFile(path: String, destination: String, overwrite: Bool) throws { + public func unzipFile(path: NSURL, destination: String, overwrite: Bool, password: String?) throws { // Check file exists at path. let fileManager = NSFileManager.defaultManager() - if fileManager.fileExistsAtPath(path) == false { + if fileManager.fileExistsAtPath(path.absoluteString) == false { throw ZipError.FileNotFound } - let zip = unzOpen(path) + let zip = unzOpen64(path.absoluteString) // Begin unzipping if unzGoToFirstFile(zip) != UNZ_OK { throw ZipError.UnzipError @@ -46,9 +46,9 @@ public class Zip { if ret != UNZ_OK { throw ZipError.UnzipError } - var fileInfo = unz_file_info() + var fileInfo = unz_file_info64() memset(&fileInfo, 0, sizeof(unz_file_info)) - ret = unzGetCurrentFileInfo(zip, &fileInfo, nil, 0, nil, 0, nil, 0) + ret = unzGetCurrentFileInfo64(zip, &fileInfo, nil, 0, nil, 0, nil, 0) if ret != UNZ_OK { unzCloseCurrentFile(zip) throw ZipError.UnzipError @@ -58,7 +58,7 @@ public class Zip { if fileName == nil { throw ZipError.UnzipError } - unzGetCurrentFileInfo(zip, &fileInfo, fileName, UInt(fileNameSize), nil, 0, nil, 0) + unzGetCurrentFileInfo64(zip, &fileInfo, fileName, UInt(fileNameSize), nil, 0, nil, 0) fileName[Int(fileInfo.size_filename)] = 0 var strPath = String.fromCString(fileName)! as NSString @@ -70,7 +70,7 @@ public class Zip { free(fileName) if (strPath.rangeOfCharacterFromSet(NSCharacterSet(charactersInString: "/\\")).location != NSNotFound) { - strPath = strPath.stringByReplacingOccurrencesOfString("\\", withString: "/") + strPath = strPath.stringByReplacingOccurrencesOfString("\\", withString: "/") } let fullPath = (destination as NSString).stringByAppendingPathComponent(strPath as String) let creationDate = NSDate() diff --git a/examples/Sample/Sample/ViewController.swift b/examples/Sample/Sample/ViewController.swift index cf2e0b2..d5cd67b 100644 --- a/examples/Sample/Sample/ViewController.swift +++ b/examples/Sample/Sample/ViewController.swift @@ -15,9 +15,10 @@ class ViewController: UIViewController { super.viewDidLoad() do { let destinationPath = tempUnzipPath()! - let fileAbsoluteUrl = NSBundle.mainBundle().pathForResource("master", ofType: "zip") + let fileAbsolutePath = NSBundle.mainBundle().pathForResource("master", ofType: "zip") + let fileAbsoluteURL = NSURL(string: fileAbsolutePath!)! print(destinationPath) - try Zip().unzipFile(fileAbsoluteUrl!, destination: destinationPath, overwrite: true) + try Zip().unzipFile(fileAbsoluteURL, destination: destinationPath, overwrite: true, password: nil) } catch { print("oops") -- 2.26.2