Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
Zip
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Jira
Jira
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
YongYue
Zip
Commits
26f376da
Commit
26f376da
authored
Jan 16, 2016
by
Roy Marmelstein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Defining quick zip functions
parent
bb7c238e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
32 deletions
+98
-32
Zip.xcodeproj/project.pbxproj
Zip.xcodeproj/project.pbxproj
+4
-0
Zip/QuickZip.swift
Zip/QuickZip.swift
+82
-0
Zip/Zip.swift
Zip/Zip.swift
+10
-30
examples/Sample/Sample/ViewController.swift
examples/Sample/Sample/ViewController.swift
+2
-2
No files found.
Zip.xcodeproj/project.pbxproj
View file @
26f376da
...
...
@@ -36,6 +36,7 @@
3430F6341C45C851007473A6
/* unzip.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
3430F62A1C45C851007473A6
/* unzip.h */
;
};
3430F6351C45C851007473A6
/* zip.c in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
3430F62B1C45C851007473A6
/* zip.c */
;
};
3430F6361C45C851007473A6
/* zip.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
3430F62C1C45C851007473A6
/* zip.h */
;
};
3443A3F61C4AB8A3004AD173
/* QuickZip.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
3443A3F51C4AB8A3004AD173
/* QuickZip.swift */
;
};
347E3A781C1DFFB500A11FD3
/* Zip.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
347E3A771C1DFFB500A11FD3
/* Zip.h */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
347E3A7F1C1DFFB500A11FD3
/* Zip.framework in Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
347E3A741C1DFFB500A11FD3
/* Zip.framework */
;
};
347E3A841C1DFFB500A11FD3
/* ZipTests.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
347E3A831C1DFFB500A11FD3
/* ZipTests.swift */
;
};
...
...
@@ -83,6 +84,7 @@
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>"
;
};
3433BFCD1C48D3EC006DF000
/* module.modulemap */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
"sourcecode.module-map"
;
path
=
module.modulemap
;
sourceTree
=
"<group>"
;
};
3443A3F51C4AB8A3004AD173
/* QuickZip.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
QuickZip.swift
;
sourceTree
=
"<group>"
;
};
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>"
;
};
347E3A791C1DFFB500A11FD3
/* Info.plist */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
text.plist.xml
;
path
=
Info.plist
;
sourceTree
=
"<group>"
;
};
...
...
@@ -182,6 +184,7 @@
347E3A771C1DFFB500A11FD3
/* Zip.h */
,
347E3A791C1DFFB500A11FD3
/* Info.plist */
,
347E3AD71C1E04C900A11FD3
/* Zip.swift */
,
3443A3F51C4AB8A3004AD173
/* QuickZip.swift */
,
);
path
=
Zip
;
sourceTree
=
"<group>"
;
...
...
@@ -330,6 +333,7 @@
3430BB2F1C484A65001143B5
/* entropy.c in Sources */
,
3430F6351C45C851007473A6
/* zip.c in Sources */
,
3430BB281C484A65001143B5
/* aescrypt.c in Sources */
,
3443A3F61C4AB8A3004AD173
/* QuickZip.swift in Sources */
,
3430BB311C484A65001143B5
/* fileenc.c in Sources */
,
3430BB381C484A65001143B5
/* pwd2key.c in Sources */
,
);
...
...
Zip/QuickZip.swift
0 → 100644
View file @
26f376da
//
// QuickZip.swift
// Zip
//
// Created by Roy Marmelstein on 16/01/2016.
// Copyright © 2016 Roy Marmelstein. All rights reserved.
//
import
Foundation
extension
Zip
{
//MARK: Quick Unzip
/**
Quick unzip a file. Unzips to a new folder inside the app's documents folder with the zip file's name.
- parameter path: Path of zipped file. NSURL.
- throws: Error if unzipping fails or if file is not found. Can be printed with a description variable.
- returns: NSURL of the destination folder.
*/
public
func
quickUnzipFile
(
path
:
NSURL
)
throws
->
NSURL
{
return
try
quickUnzipFile
(
path
,
progress
:
nil
)
}
/**
Quick unzip a file. Unzips to a new folder inside the app's documents folder with the zip file's name.
- parameter path: Path of zipped file. NSURL.
- parameter progress: A progress closure called after unzipping each file in the archive. Double value betweem 0 and 1.
- throws: Error if unzipping fails or if file is not found. Can be printed with a description variable.
- returns: NSURL of the destination folder.
*/
public
func
quickUnzipFile
(
path
:
NSURL
,
progress
:
((
progress
:
Double
)
->
())?)
throws
->
NSURL
{
guard
let
fileExtension
=
path
.
pathExtension
,
let
fileName
=
path
.
lastPathComponent
else
{
throw
ZipError
.
UnzipError
}
let
directoryName
=
fileName
.
stringByReplacingOccurrencesOfString
(
fileExtension
,
withString
:
""
)
let
destinationUrl
=
documentsUrl
.
URLByAppendingPathComponent
(
directoryName
,
isDirectory
:
true
)
try
self
.
unzipFile
(
path
,
destination
:
destinationUrl
,
overwrite
:
true
,
password
:
nil
,
progress
:
progress
)
return
destinationUrl
}
//MARK: Quick Zip
/**
Quick zip files.
- parameter paths: Array of NSURL filepaths.
- parameter fileName: File name for the resulting zip file.
- throws: rror if zipping fails.
- returns: NSURL of the destination folder.
*/
public
func
quickZipFiles
(
paths
:
[
NSURL
],
fileName
:
String
)
throws
->
NSURL
{
return
try
quickZipFiles
(
paths
,
fileName
:
fileName
,
progress
:
nil
)
}
/**
Quick zip files.
- parameter paths: Array of NSURL filepaths.
- parameter fileName: File name for the resulting zip file.
- parameter progress: A progress closure called after unzipping each file in the archive. Double value betweem 0 and 1.
- throws: rror if zipping fails.
- returns: NSURL of the destination folder.
*/
public
func
quickZipFiles
(
paths
:
[
NSURL
],
fileName
:
String
,
progress
:
((
progress
:
Double
)
->
())?)
throws
->
NSURL
{
let
destinationUrl
=
documentsUrl
.
URLByAppendingPathComponent
(
"
\(
fileName
)
.zip"
)
try
self
.
zipFiles
(
paths
,
destination
:
destinationUrl
,
password
:
nil
,
progress
:
progress
)
return
destinationUrl
}
}
\ No newline at end of file
Zip/Zip.swift
View file @
26f376da
...
...
@@ -14,6 +14,7 @@ public enum ZipError: ErrorType {
case
FileNotFound
// File not found
case
UnzipError
// Unzip error
case
ZipError
// Unzip error
case
NotAZipFileError
// Unzip error
/// Description variable
public
var
description
:
String
{
...
...
@@ -21,6 +22,7 @@ public enum ZipError: ErrorType {
case
.
FileNotFound
:
return
NSLocalizedString
(
"File not found."
,
comment
:
""
)
case
.
UnzipError
:
return
NSLocalizedString
(
"Failed to unzip zip file."
,
comment
:
""
)
case
.
ZipError
:
return
NSLocalizedString
(
"Failed to zip file."
,
comment
:
""
)
case
.
NotAZipFileError
:
return
NSLocalizedString
(
"The file path does not contain a zip file."
,
comment
:
""
)
}
}
}
...
...
@@ -28,6 +30,9 @@ public enum ZipError: ErrorType {
public
class
Zip
{
// Documents folder
let
documentsUrl
=
NSFileManager
.
defaultManager
()
.
URLsForDirectory
(
.
DocumentDirectory
,
inDomains
:
.
UserDomainMask
)[
0
]
as
NSURL
// MARK: Lifecycle
/**
...
...
@@ -40,19 +45,6 @@ public class Zip {
// MARK: Unzip
/**
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
,
progress
:
nil
)
}
/**
Unzip file
...
...
@@ -60,6 +52,7 @@ public class Zip {
- parameter destination: Path to unzip to. NSURL.
- parameter overwrite: Overwrite bool.
- parameter password: Optional password if file is protected.
- parameter progress: A progress closure called after unzipping each file in the archive. Double value betweem 0 and 1.
- throws: Error if unzipping fails or if fail is not found. Can be printed with a description variable.
*/
...
...
@@ -166,26 +159,13 @@ public class Zip {
// MARK: Zip
/**
Quick zip files.
- parameter paths: Array of NSURL filepaths.
- parameter fileName: File name for the resulting zip file.
- throws: rror if zipping fails.
*/
public
func
zipFiles
(
paths
:
[
NSURL
],
fileName
:
String
)
throws
{
var
documentsUrl
=
NSFileManager
.
defaultManager
()
.
URLsForDirectory
(
.
DocumentDirectory
,
inDomains
:
.
UserDomainMask
)[
0
]
as
NSURL
documentsUrl
=
documentsUrl
.
URLByAppendingPathComponent
(
"
\(
fileName
)
.zip"
)
try
self
.
zipFiles
(
paths
,
destination
:
documentsUrl
,
password
:
nil
,
progress
:
nil
)
}
/**
Zip files.
- parameter paths: Array of NSURL filepaths.
- parameter destination: Destination NSURL, should lead to a .zip filepath.
- parameter password: Password string. Optional.
- parameter progress: A progress closure called after unzipping each file in the archive. Double value betweem 0 and 1.
- throws: Error if zipping fails.
*/
...
...
examples/Sample/Sample/ViewController.swift
View file @
26f376da
...
...
@@ -18,8 +18,8 @@ class ViewController: UIViewController {
let
fileAbsolutePath
=
NSBundle
.
mainBundle
()
.
pathForResource
(
"master"
,
ofType
:
"zip"
)
let
fileAbsoluteURL
=
NSURL
(
string
:
fileAbsolutePath
!
)
!
print
(
destinationPath
)
try
Zip
()
.
u
nzipFile
(
fileAbsoluteURL
)
try
Zip
()
.
z
ipFiles
([
fileAbsoluteURL
],
fileName
:
"zipTest"
)
try
Zip
()
.
quickU
nzipFile
(
fileAbsoluteURL
)
try
Zip
()
.
quickZ
ipFiles
([
fileAbsoluteURL
],
fileName
:
"zipTest"
)
}
catch
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment