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
d9bf08dc
Commit
d9bf08dc
authored
Apr 29, 2016
by
Roy Marmelstein
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into jozsef-vesza-include-cbz
Conflicts: Zip/Zip.swift ZipTests/ZipTests.swift
parents
03aab4bf
82686f86
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
113 additions
and
40 deletions
+113
-40
Zip/QuickZip.swift
Zip/QuickZip.swift
+28
-22
Zip/Zip.swift
Zip/Zip.swift
+39
-16
ZipTests/ZipTests.swift
ZipTests/ZipTests.swift
+46
-2
No files found.
Zip/QuickZip.swift
View file @
d9bf08dc
...
@@ -33,6 +33,8 @@ extension Zip {
...
@@ -33,6 +33,8 @@ extension Zip {
- throws: Error if unzipping fails or if file is not found. Can be printed with a description variable.
- throws: Error if unzipping fails or if file is not found. Can be printed with a description variable.
- notes: Supports implicit progress composition
- returns: NSURL of the destination folder.
- returns: NSURL of the destination folder.
*/
*/
public
class
func
quickUnzipFile
(
path
:
NSURL
,
progress
:
((
progress
:
Double
)
->
())?)
throws
->
NSURL
{
public
class
func
quickUnzipFile
(
path
:
NSURL
,
progress
:
((
progress
:
Double
)
->
())?)
throws
->
NSURL
{
...
@@ -57,6 +59,8 @@ extension Zip {
...
@@ -57,6 +59,8 @@ extension Zip {
- throws: Error if zipping fails.
- throws: Error if zipping fails.
- notes: Supports implicit progress composition
- returns: NSURL of the destination folder.
- returns: NSURL of the destination folder.
*/
*/
public
class
func
quickZipFiles
(
paths
:
[
NSURL
],
fileName
:
String
)
throws
->
NSURL
{
public
class
func
quickZipFiles
(
paths
:
[
NSURL
],
fileName
:
String
)
throws
->
NSURL
{
...
@@ -72,6 +76,8 @@ extension Zip {
...
@@ -72,6 +76,8 @@ extension Zip {
- throws: Error if zipping fails.
- throws: Error if zipping fails.
- notes: Supports implicit progress composition
- returns: NSURL of the destination folder.
- returns: NSURL of the destination folder.
*/
*/
public
class
func
quickZipFiles
(
paths
:
[
NSURL
],
fileName
:
String
,
progress
:
((
progress
:
Double
)
->
())?)
throws
->
NSURL
{
public
class
func
quickZipFiles
(
paths
:
[
NSURL
],
fileName
:
String
,
progress
:
((
progress
:
Double
)
->
())?)
throws
->
NSURL
{
...
...
Zip/Zip.swift
View file @
d9bf08dc
...
@@ -53,6 +53,8 @@ public class Zip {
...
@@ -53,6 +53,8 @@ public class Zip {
- 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 unzipping fails or if fail is not found. Can be printed with a description variable.
- throws: Error if unzipping fails or if fail is not found. Can be printed with a description variable.
- notes: Supports implicit progress composition
*/
*/
public
class
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
{
...
@@ -82,6 +84,11 @@ public class Zip {
...
@@ -82,6 +84,11 @@ public class Zip {
totalSize
+=
attributeFileSize
totalSize
+=
attributeFileSize
}
}
let
progressTracker
=
NSProgress
(
totalUnitCount
:
Int64
(
totalSize
))
progressTracker
.
cancellable
=
false
progressTracker
.
pausable
=
false
progressTracker
.
kind
=
NSProgressKindFile
// Begin unzipping
// Begin unzipping
let
zip
=
unzOpen64
(
path
)
let
zip
=
unzOpen64
(
path
)
if
unzGoToFirstFile
(
zip
)
!=
UNZ_OK
{
if
unzGoToFirstFile
(
zip
)
!=
UNZ_OK
{
...
@@ -165,6 +172,8 @@ public class Zip {
...
@@ -165,6 +172,8 @@ public class Zip {
progressHandler
(
progress
:
(
currentPosition
/
totalSize
))
progressHandler
(
progress
:
(
currentPosition
/
totalSize
))
}
}
progressTracker
.
completedUnitCount
=
Int64
(
currentPosition
)
}
while
(
ret
==
UNZ_OK
&&
ret
!=
UNZ_END_OF_LIST_OF_FILE
)
}
while
(
ret
==
UNZ_OK
&&
ret
!=
UNZ_END_OF_LIST_OF_FILE
)
// Completed. Update progress handler.
// Completed. Update progress handler.
...
@@ -172,6 +181,8 @@ public class Zip {
...
@@ -172,6 +181,8 @@ public class Zip {
progressHandler
(
progress
:
1.0
)
progressHandler
(
progress
:
1.0
)
}
}
progressTracker
.
completedUnitCount
=
Int64
(
totalSize
)
}
}
// MARK: Zip
// MARK: Zip
...
@@ -185,6 +196,8 @@ public class Zip {
...
@@ -185,6 +196,8 @@ public class Zip {
- 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
*/
*/
public
class
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
{
...
@@ -218,6 +231,11 @@ public class Zip {
...
@@ -218,6 +231,11 @@ public class Zip {
catch
{}
catch
{}
}
}
let
progressTracker
=
NSProgress
(
totalUnitCount
:
Int64
(
totalSize
))
progressTracker
.
cancellable
=
false
progressTracker
.
pausable
=
false
progressTracker
.
kind
=
NSProgressKindFile
// Begin Zipping
// Begin Zipping
let
zip
=
zipOpen
(
destinationPath
,
APPEND_STATUS_CREATE
)
let
zip
=
zipOpen
(
destinationPath
,
APPEND_STATUS_CREATE
)
for
path
in
processedPaths
{
for
path
in
processedPaths
{
...
@@ -268,6 +286,8 @@ public class Zip {
...
@@ -268,6 +286,8 @@ public class Zip {
progressHandler
(
progress
:
(
currentPosition
/
totalSize
))
progressHandler
(
progress
:
(
currentPosition
/
totalSize
))
}
}
progressTracker
.
completedUnitCount
=
Int64
(
currentPosition
)
zipCloseFileInZip
(
zip
)
zipCloseFileInZip
(
zip
)
free
(
buffer
)
free
(
buffer
)
fclose
(
input
)
fclose
(
input
)
...
@@ -279,6 +299,8 @@ public class Zip {
...
@@ -279,6 +299,8 @@ public class Zip {
if
let
progressHandler
=
progress
{
if
let
progressHandler
=
progress
{
progressHandler
(
progress
:
1.0
)
progressHandler
(
progress
:
1.0
)
}
}
progressTracker
.
completedUnitCount
=
Int64
(
totalSize
)
}
}
/**
/**
...
@@ -294,4 +316,5 @@ public class Zip {
...
@@ -294,4 +316,5 @@ public class Zip {
return
!
[
"zip"
,
"cbz"
]
.
contains
(
fileExtension
)
return
!
[
"zip"
,
"cbz"
]
.
contains
(
fileExtension
)
}
}
}
}
\ No newline at end of file
ZipTests/ZipTests.swift
View file @
d9bf08dc
...
@@ -84,9 +84,11 @@ class ZipTests: XCTestCase {
...
@@ -84,9 +84,11 @@ class ZipTests: XCTestCase {
do
{
do
{
let
filePath
=
NSBundle
(
forClass
:
ZipTests
.
self
)
.
URLForResource
(
"bb8"
,
withExtension
:
"zip"
)
!
let
filePath
=
NSBundle
(
forClass
:
ZipTests
.
self
)
.
URLForResource
(
"bb8"
,
withExtension
:
"zip"
)
!
let
documentsFolder
=
NSFileManager
.
defaultManager
()
.
URLsForDirectory
(
.
DocumentDirectory
,
inDomains
:
.
UserDomainMask
)[
0
]
as
NSURL
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
)
print
(
progress
)
})
})
let
fileManager
=
NSFileManager
.
defaultManager
()
let
fileManager
=
NSFileManager
.
defaultManager
()
XCTAssertTrue
(
fileManager
.
fileExistsAtPath
(
documentsFolder
.
path
!
))
XCTAssertTrue
(
fileManager
.
fileExistsAtPath
(
documentsFolder
.
path
!
))
}
}
...
@@ -95,6 +97,48 @@ class ZipTests: XCTestCase {
...
@@ -95,6 +97,48 @@ class ZipTests: XCTestCase {
}
}
}
}
func
testImplicitProgressUnzip
()
{
do
{
let
progress
=
NSProgress
()
progress
.
totalUnitCount
=
1
let
filePath
=
NSBundle
(
forClass
:
ZipTests
.
self
)
.
URLForResource
(
"bb8"
,
withExtension
:
"zip"
)
!
let
documentsFolder
=
NSFileManager
.
defaultManager
()
.
URLsForDirectory
(
.
DocumentDirectory
,
inDomains
:
.
UserDomainMask
)[
0
]
as
NSURL
progress
.
becomeCurrentWithPendingUnitCount
(
1
)
try
Zip
.
unzipFile
(
filePath
,
destination
:
documentsFolder
,
overwrite
:
true
,
password
:
"password"
,
progress
:
nil
)
progress
.
resignCurrent
()
XCTAssertTrue
(
progress
.
totalUnitCount
==
progress
.
completedUnitCount
)
}
catch
{
XCTFail
()
}
}
func
testImplicitProgressZip
()
{
do
{
let
progress
=
NSProgress
()
progress
.
totalUnitCount
=
1
let
imageURL1
=
NSBundle
(
forClass
:
ZipTests
.
self
)
.
URLForResource
(
"3crBXeO"
,
withExtension
:
"gif"
)
!
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"
)
progress
.
becomeCurrentWithPendingUnitCount
(
1
)
try
Zip
.
zipFiles
([
imageURL1
,
imageURL2
],
zipFilePath
:
zipFilePath
,
password
:
nil
,
progress
:
nil
)
progress
.
resignCurrent
()
XCTAssertTrue
(
progress
.
totalUnitCount
==
progress
.
completedUnitCount
)
}
catch
{
XCTFail
()
}
}
func
testQuickZip
()
{
func
testQuickZip
()
{
do
{
do
{
let
imageURL1
=
NSBundle
(
forClass
:
ZipTests
.
self
)
.
URLForResource
(
"3crBXeO"
,
withExtension
:
"gif"
)
!
let
imageURL1
=
NSBundle
(
forClass
:
ZipTests
.
self
)
.
URLForResource
(
"3crBXeO"
,
withExtension
:
"gif"
)
!
...
...
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