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
a81c88ac
Commit
a81c88ac
authored
Jan 19, 2016
by
Roy Marmelstein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make all zip functions class functions for nicer syntax
parent
a9d9a2bb
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
17 deletions
+22
-17
Zip/QuickZip.swift
Zip/QuickZip.swift
+6
-4
Zip/Zip.swift
Zip/Zip.swift
+8
-5
ZipTests/ZipTests.swift
ZipTests/ZipTests.swift
+8
-8
No files found.
Zip/QuickZip.swift
View file @
a81c88ac
...
...
@@ -21,7 +21,7 @@ extension Zip {
- returns: NSURL of the destination folder.
*/
public
func
quickUnzipFile
(
path
:
NSURL
)
throws
->
NSURL
{
public
class
func
quickUnzipFile
(
path
:
NSURL
)
throws
->
NSURL
{
return
try
quickUnzipFile
(
path
,
progress
:
nil
)
}
...
...
@@ -35,7 +35,8 @@ extension Zip {
- returns: NSURL of the destination folder.
*/
public
func
quickUnzipFile
(
path
:
NSURL
,
progress
:
((
progress
:
Double
)
->
())?)
throws
->
NSURL
{
public
class
func
quickUnzipFile
(
path
:
NSURL
,
progress
:
((
progress
:
Double
)
->
())?)
throws
->
NSURL
{
let
fileManager
=
NSFileManager
.
defaultManager
()
guard
let
fileExtension
=
path
.
pathExtension
,
let
fileName
=
path
.
lastPathComponent
else
{
throw
ZipError
.
UnzipFail
}
...
...
@@ -58,7 +59,7 @@ extension Zip {
- returns: NSURL of the destination folder.
*/
public
func
quickZipFiles
(
paths
:
[
NSURL
],
fileName
:
String
)
throws
->
NSURL
{
public
class
func
quickZipFiles
(
paths
:
[
NSURL
],
fileName
:
String
)
throws
->
NSURL
{
return
try
quickZipFiles
(
paths
,
fileName
:
fileName
,
progress
:
nil
)
}
...
...
@@ -73,7 +74,8 @@ extension Zip {
- returns: NSURL of the destination folder.
*/
public
func
quickZipFiles
(
paths
:
[
NSURL
],
fileName
:
String
,
progress
:
((
progress
:
Double
)
->
())?)
throws
->
NSURL
{
public
class
func
quickZipFiles
(
paths
:
[
NSURL
],
fileName
:
String
,
progress
:
((
progress
:
Double
)
->
())?)
throws
->
NSURL
{
let
fileManager
=
NSFileManager
.
defaultManager
()
let
documentsUrl
=
fileManager
.
URLsForDirectory
(
.
DocumentDirectory
,
inDomains
:
.
UserDomainMask
)[
0
]
as
NSURL
let
destinationUrl
=
documentsUrl
.
URLByAppendingPathComponent
(
"
\(
fileName
)
.zip"
)
try
self
.
zipFiles
(
paths
,
zipFilePath
:
destinationUrl
,
password
:
nil
,
progress
:
progress
)
...
...
Zip/Zip.swift
View file @
a81c88ac
...
...
@@ -31,9 +31,6 @@ public enum ZipError: ErrorType {
/// Zip class
public
class
Zip
{
// File manager
let
fileManager
=
NSFileManager
.
defaultManager
()
// MARK: Lifecycle
/**
...
...
@@ -58,7 +55,10 @@ public class Zip {
- throws: Error if unzipping fails or if fail is not found. Can be printed with a description variable.
*/
public
func
unzipFile
(
zipFilePath
:
NSURL
,
destination
:
NSURL
,
overwrite
:
Bool
,
password
:
String
?,
progress
:
((
progress
:
Double
)
->
())?)
throws
{
public
class
func
unzipFile
(
zipFilePath
:
NSURL
,
destination
:
NSURL
,
overwrite
:
Bool
,
password
:
String
?,
progress
:
((
progress
:
Double
)
->
())?)
throws
{
// File manager
let
fileManager
=
NSFileManager
.
defaultManager
()
// Check whether a zip file exists at path.
guard
let
path
=
zipFilePath
.
path
,
let
destinationPath
=
destination
.
path
else
{
...
...
@@ -185,7 +185,10 @@ public class Zip {
- throws: Error if zipping fails.
*/
public
func
zipFiles
(
paths
:
[
NSURL
],
zipFilePath
:
NSURL
,
password
:
String
?,
progress
:
((
progress
:
Double
)
->
())?)
throws
{
public
class
func
zipFiles
(
paths
:
[
NSURL
],
zipFilePath
:
NSURL
,
password
:
String
?,
progress
:
((
progress
:
Double
)
->
())?)
throws
{
// File manager
let
fileManager
=
NSFileManager
.
defaultManager
()
// Check whether a zip file exists at path.
guard
let
destinationPath
=
zipFilePath
.
path
else
{
...
...
ZipTests/ZipTests.swift
View file @
a81c88ac
...
...
@@ -22,7 +22,7 @@ class ZipTests: XCTestCase {
func
testQuickUnzip
()
{
do
{
let
filePath
=
NSBundle
(
forClass
:
ZipTests
.
self
)
.
URLForResource
(
"bb8"
,
withExtension
:
"zip"
)
!
let
destinationURL
=
try
Zip
()
.
quickUnzipFile
(
filePath
)
let
destinationURL
=
try
Zip
.
quickUnzipFile
(
filePath
)
let
fileManager
=
NSFileManager
.
defaultManager
()
XCTAssertTrue
(
fileManager
.
fileExistsAtPath
(
destinationURL
.
path
!
))
}
...
...
@@ -35,7 +35,7 @@ class ZipTests: XCTestCase {
do
{
let
filePathURL
=
NSBundle
(
forClass
:
ZipTests
.
self
)
.
resourcePath
let
filePath
=
NSURL
(
string
:
"
\(
filePathURL
!
)
/bb9.zip"
)
let
destinationURL
=
try
Zip
()
.
quickUnzipFile
(
filePath
!
)
let
destinationURL
=
try
Zip
.
quickUnzipFile
(
filePath
!
)
let
fileManager
=
NSFileManager
.
defaultManager
()
XCTAssertFalse
(
fileManager
.
fileExistsAtPath
(
destinationURL
.
path
!
))
}
...
...
@@ -47,7 +47,7 @@ class ZipTests: XCTestCase {
func
testQuickUnzipNonZipPath
()
{
do
{
let
filePath
=
NSBundle
(
forClass
:
ZipTests
.
self
)
.
URLForResource
(
"3crBXeO"
,
withExtension
:
"gif"
)
!
let
destinationURL
=
try
Zip
()
.
quickUnzipFile
(
filePath
)
let
destinationURL
=
try
Zip
.
quickUnzipFile
(
filePath
)
let
fileManager
=
NSFileManager
.
defaultManager
()
XCTAssertFalse
(
fileManager
.
fileExistsAtPath
(
destinationURL
.
path
!
))
}
...
...
@@ -59,7 +59,7 @@ class ZipTests: XCTestCase {
func
testQuickUnzipProgress
()
{
do
{
let
filePath
=
NSBundle
(
forClass
:
ZipTests
.
self
)
.
URLForResource
(
"bb8"
,
withExtension
:
"zip"
)
!
try
Zip
()
.
quickUnzipFile
(
filePath
,
progress
:
{
(
progress
)
->
()
in
try
Zip
.
quickUnzipFile
(
filePath
,
progress
:
{
(
progress
)
->
()
in
XCTAssert
(
true
)
})
}
...
...
@@ -71,7 +71,7 @@ class ZipTests: XCTestCase {
func
testQuickUnzipOnlineURL
()
{
do
{
let
filePath
=
NSURL
(
string
:
"http://www.google.com/google.zip"
)
!
let
destinationURL
=
try
Zip
()
.
quickUnzipFile
(
filePath
)
let
destinationURL
=
try
Zip
.
quickUnzipFile
(
filePath
)
let
fileManager
=
NSFileManager
.
defaultManager
()
XCTAssertFalse
(
fileManager
.
fileExistsAtPath
(
destinationURL
.
path
!
))
}
...
...
@@ -84,7 +84,7 @@ class ZipTests: XCTestCase {
do
{
let
filePath
=
NSBundle
(
forClass
:
ZipTests
.
self
)
.
URLForResource
(
"bb8"
,
withExtension
:
"zip"
)
!
let
documentsFolder
=
NSFileManager
.
defaultManager
()
.
URLsForDirectory
(
.
DocumentDirectory
,
inDomains
:
.
UserDomainMask
)[
0
]
as
NSURL
try
Zip
()
.
unzipFile
(
filePath
,
destination
:
documentsFolder
,
overwrite
:
true
,
password
:
"password"
,
progress
:
{
(
progress
)
->
()
in
try
Zip
.
unzipFile
(
filePath
,
destination
:
documentsFolder
,
overwrite
:
true
,
password
:
"password"
,
progress
:
{
(
progress
)
->
()
in
print
(
progress
)
})
let
fileManager
=
NSFileManager
.
defaultManager
()
...
...
@@ -99,7 +99,7 @@ class ZipTests: XCTestCase {
do
{
let
imageURL1
=
NSBundle
(
forClass
:
ZipTests
.
self
)
.
URLForResource
(
"3crBXeO"
,
withExtension
:
"gif"
)
!
let
imageURL2
=
NSBundle
(
forClass
:
ZipTests
.
self
)
.
URLForResource
(
"kYkLkPf"
,
withExtension
:
"gif"
)
!
let
destinationURL
=
try
Zip
()
.
quickZipFiles
([
imageURL1
,
imageURL2
],
fileName
:
"archive"
)
let
destinationURL
=
try
Zip
.
quickZipFiles
([
imageURL1
,
imageURL2
],
fileName
:
"archive"
)
let
fileManager
=
NSFileManager
.
defaultManager
()
XCTAssertTrue
(
fileManager
.
fileExistsAtPath
(
destinationURL
.
path
!
))
}
...
...
@@ -114,7 +114,7 @@ class ZipTests: XCTestCase {
let
imageURL2
=
NSBundle
(
forClass
:
ZipTests
.
self
)
.
URLForResource
(
"kYkLkPf"
,
withExtension
:
"gif"
)
!
let
documentsFolder
=
NSFileManager
.
defaultManager
()
.
URLsForDirectory
(
.
DocumentDirectory
,
inDomains
:
.
UserDomainMask
)[
0
]
as
NSURL
let
zipFilePath
=
documentsFolder
.
URLByAppendingPathComponent
(
"archive.zip"
)
try
Zip
()
.
zipFiles
([
imageURL1
,
imageURL2
],
zipFilePath
:
zipFilePath
,
password
:
nil
,
progress
:
{
(
progress
)
->
()
in
try
Zip
.
zipFiles
([
imageURL1
,
imageURL2
],
zipFilePath
:
zipFilePath
,
password
:
nil
,
progress
:
{
(
progress
)
->
()
in
print
(
progress
)
})
let
fileManager
=
NSFileManager
.
defaultManager
()
...
...
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