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
7856c0f9
Commit
7856c0f9
authored
Sep 18, 2016
by
Roy Marmelstein
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'tbergmen-master' into libraryincluded
parents
f80c0038
958f359d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
3 deletions
+25
-3
Zip/Zip.swift
Zip/Zip.swift
+25
-3
No files found.
Zip/Zip.swift
View file @
7856c0f9
...
@@ -28,6 +28,26 @@ public enum ZipError: Error {
...
@@ -28,6 +28,26 @@ public enum ZipError: Error {
}
}
}
}
public
enum
ZipCompression
:
Int
{
case
NoCompression
case
BestSpeed
case
DefaultCompression
case
BestCompression
internal
var
minizipCompression
:
Int32
{
switch
self
{
case
.
NoCompression
:
return
Z_NO_COMPRESSION
case
.
BestSpeed
:
return
Z_BEST_SPEED
case
.
DefaultCompression
:
return
Z_DEFAULT_COMPRESSION
case
.
BestCompression
:
return
Z_BEST_COMPRESSION
}
}
}
/// Zip class
/// Zip class
public
class
Zip
{
public
class
Zip
{
...
@@ -197,19 +217,21 @@ public class Zip {
...
@@ -197,19 +217,21 @@ public class Zip {
// MARK: Zip
// MARK: Zip
/**
/**
Zip files.
Zip files.
- parameter paths: Array of NSURL filepaths.
- parameter paths: Array of NSURL filepaths.
- parameter zipFilePath: Destination NSURL, should lead to a .zip filepath.
- parameter zipFilePath: Destination NSURL, should lead to a .zip filepath.
- parameter password: Password string. Optional.
- parameter password: Password string. Optional.
- parameter compression: Compression strategy
- parameter progress: A progress closure called after unzipping each file in the archive. Double value betweem 0 and 1.
- parameter progress: A progress closure called after unzipping each file in the archive. Double value betweem 0 and 1.
- throws: Error if zipping fails.
- throws: Error if zipping fails.
- notes: Supports implicit progress composition
- notes: Supports implicit progress composition
*/
*/
public
class
func
zipFiles
(
_
paths
:
[
URL
],
zipFilePath
:
URL
,
password
:
String
?
,
progress
:
((
_
progress
:
Double
)
->
())?)
throws
{
public
class
func
zipFiles
(
paths
:
[
URL
],
zipFilePath
:
URL
,
password
:
String
?,
compression
:
ZipCompression
=
.
DefaultCompression
,
progress
:
((
_
progress
:
Double
)
->
())?)
throws
{
// File manager
// File manager
let
fileManager
=
FileManager
.
default
let
fileManager
=
FileManager
.
default
...
@@ -275,10 +297,10 @@ public class Zip {
...
@@ -275,10 +297,10 @@ public class Zip {
catch
{}
catch
{}
let
buffer
=
malloc
(
chunkSize
)
let
buffer
=
malloc
(
chunkSize
)
if
let
password
=
password
,
let
fileName
=
fileName
{
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
)
zipOpenNewFileInZip3
(
zip
,
fileName
,
&
zipInfo
,
nil
,
0
,
nil
,
0
,
nil
,
Z_DEFLATED
,
compression
.
minizipCompression
,
0
,
-
MAX_WBITS
,
DEF_MEM_LEVEL
,
Z_DEFAULT_STRATEGY
,
password
,
0
)
}
}
else
if
let
fileName
=
fileName
{
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
)
zipOpenNewFileInZip3
(
zip
,
fileName
,
&
zipInfo
,
nil
,
0
,
nil
,
0
,
nil
,
Z_DEFLATED
,
compression
.
minizipCompression
,
0
,
-
MAX_WBITS
,
DEF_MEM_LEVEL
,
Z_DEFAULT_STRATEGY
,
nil
,
0
)
}
}
else
{
else
{
throw
ZipError
.
zipFail
throw
ZipError
.
zipFail
...
...
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