Commit 7b888c22 authored by Roy Marmelstein's avatar Roy Marmelstein

Zip improvements

parent 550a0606
...@@ -74,7 +74,6 @@ ...@@ -74,7 +74,6 @@
3430BB231C484A65001143B5 /* pwd2key.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pwd2key.h; sourceTree = "<group>"; }; 3430BB231C484A65001143B5 /* pwd2key.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pwd2key.h; sourceTree = "<group>"; };
3430BB241C484A65001143B5 /* sha1.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sha1.c; sourceTree = "<group>"; }; 3430BB241C484A65001143B5 /* sha1.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sha1.c; sourceTree = "<group>"; };
3430BB251C484A65001143B5 /* sha1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sha1.h; sourceTree = "<group>"; }; 3430BB251C484A65001143B5 /* sha1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sha1.h; sourceTree = "<group>"; };
3430BB3E1C484D39001143B5 /* module.modulemap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "sourcecode.module-map"; name = module.modulemap; path = Zip/module.modulemap; sourceTree = SOURCE_ROOT; };
3430F61F1C45C805007473A6 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; 3430F61F1C45C805007473A6 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
3430F6221C45C851007473A6 /* crypt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = crypt.h; sourceTree = "<group>"; }; 3430F6221C45C851007473A6 /* crypt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = crypt.h; sourceTree = "<group>"; };
3430F6241C45C851007473A6 /* ioapi.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ioapi.c; sourceTree = "<group>"; }; 3430F6241C45C851007473A6 /* ioapi.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ioapi.c; sourceTree = "<group>"; };
...@@ -83,6 +82,7 @@ ...@@ -83,6 +82,7 @@
3430F62A1C45C851007473A6 /* unzip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = unzip.h; sourceTree = "<group>"; }; 3430F62A1C45C851007473A6 /* unzip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = unzip.h; sourceTree = "<group>"; };
3430F62B1C45C851007473A6 /* zip.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip.c; sourceTree = "<group>"; }; 3430F62B1C45C851007473A6 /* zip.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip.c; sourceTree = "<group>"; };
3430F62C1C45C851007473A6 /* zip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = zip.h; sourceTree = "<group>"; }; 3430F62C1C45C851007473A6 /* zip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = zip.h; sourceTree = "<group>"; };
3433BFCD1C48D3EC006DF000 /* module.modulemap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = "<group>"; };
347E3A741C1DFFB500A11FD3 /* Zip.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Zip.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 347E3A741C1DFFB500A11FD3 /* Zip.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Zip.framework; sourceTree = BUILT_PRODUCTS_DIR; };
347E3A771C1DFFB500A11FD3 /* Zip.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Zip.h; sourceTree = "<group>"; }; 347E3A771C1DFFB500A11FD3 /* Zip.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Zip.h; sourceTree = "<group>"; };
347E3A791C1DFFB500A11FD3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 347E3A791C1DFFB500A11FD3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
...@@ -146,9 +146,9 @@ ...@@ -146,9 +146,9 @@
3430BB0F1C484A65001143B5 /* aes */, 3430BB0F1C484A65001143B5 /* aes */,
3430F6221C45C851007473A6 /* crypt.h */, 3430F6221C45C851007473A6 /* crypt.h */,
3430F6241C45C851007473A6 /* ioapi.c */, 3430F6241C45C851007473A6 /* ioapi.c */,
3433BFCD1C48D3EC006DF000 /* module.modulemap */,
3430F6251C45C851007473A6 /* ioapi.h */, 3430F6251C45C851007473A6 /* ioapi.h */,
3430F6291C45C851007473A6 /* unzip.c */, 3430F6291C45C851007473A6 /* unzip.c */,
3430BB3E1C484D39001143B5 /* module.modulemap */,
3430F62A1C45C851007473A6 /* unzip.h */, 3430F62A1C45C851007473A6 /* unzip.h */,
3430F62B1C45C851007473A6 /* zip.c */, 3430F62B1C45C851007473A6 /* zip.c */,
3430F62C1C45C851007473A6 /* zip.h */, 3430F62C1C45C851007473A6 /* zip.h */,
......
...@@ -157,11 +157,13 @@ public class Zip { ...@@ -157,11 +157,13 @@ public class Zip {
Quick zip files. Quick zip files.
- parameter paths: Array of NSURL filepaths. - parameter paths: Array of NSURL filepaths.
- parameter fileName: File name for the resulting zip file.
- throws: rror if zipping fails. - throws: rror if zipping fails.
*/ */
public func zipFiles(paths: [NSURL]) throws { public func zipFiles(paths: [NSURL], fileName: String) throws {
let documentsUrl = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL var documentsUrl = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL
documentsUrl = documentsUrl.URLByAppendingPathComponent("\(fileName).zip")
try self.zipFiles(paths, destination: documentsUrl, password: nil) try self.zipFiles(paths, destination: documentsUrl, password: nil)
} }
...@@ -198,7 +200,15 @@ public class Zip { ...@@ -198,7 +200,15 @@ public class Zip {
} }
catch {} catch {}
let buffer = malloc(chunkSize) let buffer = malloc(chunkSize)
zipOpenNewFileInZip3(zip, fileName!, &zipInfo, nil, 0, nil, 0, nil,Z_DEFLATED, Z_DEFAULT_COMPRESSION, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, password!, 0) if let password = password, let fileName = fileName {
zipOpenNewFileInZip3(zip, fileName, &zipInfo, nil, 0, nil, 0, nil,Z_DEFLATED, Z_DEFAULT_COMPRESSION, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, password, 0)
}
else if let fileName = fileName {
zipOpenNewFileInZip3(zip, fileName, &zipInfo, nil, 0, nil, 0, nil,Z_DEFLATED, Z_DEFAULT_COMPRESSION, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, nil, 0)
}
else {
throw ZipError.ZipError
}
var len: Int = 0 var len: Int = 0
while (feof(input) == 0) { while (feof(input) == 0) {
len = fread(buffer, 1, chunkSize, input) len = fread(buffer, 1, chunkSize, input)
......
module minizip [system][extern_c] {
header "unzip.h"
header "zip.h"
export *
}
...@@ -19,6 +19,8 @@ class ViewController: UIViewController { ...@@ -19,6 +19,8 @@ class ViewController: UIViewController {
let fileAbsoluteURL = NSURL(string: fileAbsolutePath!)! let fileAbsoluteURL = NSURL(string: fileAbsolutePath!)!
print(destinationPath) print(destinationPath)
try Zip().unzipFile(fileAbsoluteURL) try Zip().unzipFile(fileAbsoluteURL)
try Zip().zipFiles([fileAbsoluteURL], fileName: "zipTest")
} }
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