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
c8d9230b
Commit
c8d9230b
authored
Aug 08, 2016
by
Pavel Hlavnicka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes for XC8 beta 4
parent
9d44d606
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
70 additions
and
77 deletions
+70
-77
Zip.xcodeproj/project.xcworkspace/xcshareddata/Zip.xcscmblueprint
...eproj/project.xcworkspace/xcshareddata/Zip.xcscmblueprint
+1
-1
Zip/QuickZip.swift
Zip/QuickZip.swift
+7
-6
Zip/Zip.swift
Zip/Zip.swift
+11
-13
Zip/ZipUtilities.swift
Zip/ZipUtilities.swift
+10
-16
ZipTests/ZipTests.swift
ZipTests/ZipTests.swift
+41
-41
No files found.
Zip.xcodeproj/project.xcworkspace/xcshareddata/Zip.xcscmblueprint
View file @
c8d9230b
...
...
@@ -10,7 +10,7 @@
"DVTSourceControlWorkspaceBlueprintIdentifierKey" : "F3707899-72AE-49DA-9BDD-5CB0B64CF03A",
"DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : {
"8DA5B175D3FDB92A3B3CCBD4109A734F1316A3DD" : "Zip\/Zip\/minizip\/",
"3DD768C8AB2D6A2647C9EF99992D3CC5820E77C4" : "Zip\/"
"3DD768C8AB2D6A2647C9EF99992D3CC5820E77C4" : "Zip
-swift3
\/"
},
"DVTSourceControlWorkspaceBlueprintNameKey" : "Zip",
"DVTSourceControlWorkspaceBlueprintVersion" : 204,
...
...
Zip/QuickZip.swift
View file @
c8d9230b
...
...
@@ -39,13 +39,14 @@ extension Zip {
*/
public
class
func
quickUnzipFile
(
_
path
:
URL
,
progress
:
((
progress
:
Double
)
->
())?)
throws
->
URL
{
let
fileManager
=
FileManager
.
default
guard
let
fileExtension
=
path
.
pathExtension
,
let
fileName
=
path
.
lastPathComponent
else
{
throw
ZipError
.
unzipFail
}
let
fileExtension
=
path
.
pathExtension
let
fileName
=
path
.
lastPathComponent
let
directoryName
=
fileName
.
replacingOccurrences
(
of
:
".
\(
fileExtension
)
"
,
with
:
""
)
let
documentsUrl
=
fileManager
.
urls
ForDirectory
(
.
documentDirectory
,
inDomains
:
.
userDomainMask
)[
0
]
as
URL
let
documentsUrl
=
fileManager
.
urls
(
for
:
.
documentDirectory
,
in
:
.
userDomainMask
)[
0
]
as
URL
do
{
let
destinationUrl
=
try
documentsUrl
.
appendingPathComponent
(
directoryName
,
isDirectory
:
true
)
let
destinationUrl
=
documentsUrl
.
appendingPathComponent
(
directoryName
,
isDirectory
:
true
)
try
self
.
unzipFile
(
path
,
destination
:
destinationUrl
,
overwrite
:
true
,
password
:
nil
,
progress
:
progress
)
return
destinationUrl
}
catch
{
...
...
@@ -86,7 +87,7 @@ extension Zip {
*/
public
class
func
quickZipFiles
(
_
paths
:
[
URL
],
fileName
:
String
,
progress
:
((
progress
:
Double
)
->
())?)
throws
->
URL
{
let
fileManager
=
FileManager
.
default
let
documentsUrl
=
fileManager
.
urls
ForDirectory
(
.
documentDirectory
,
inDomains
:
.
userDomainMask
)[
0
]
as
URL
let
documentsUrl
=
fileManager
.
urls
(
for
:
.
documentDirectory
,
in
:
.
userDomainMask
)[
0
]
as
URL
let
destinationUrl
=
try!
documentsUrl
.
appendingPathComponent
(
"
\(
fileName
)
.zip"
)
try
self
.
zipFiles
(
paths
,
zipFilePath
:
destinationUrl
,
password
:
nil
,
progress
:
progress
)
return
destinationUrl
...
...
Zip/Zip.swift
View file @
c8d9230b
...
...
@@ -10,7 +10,7 @@ import Foundation
import
minizip
/// Zip error type
public
enum
ZipError
:
Error
Protocol
{
public
enum
ZipError
:
Error
{
/// File not found
case
fileNotFound
/// Unzip fail
...
...
@@ -68,9 +68,8 @@ public class Zip {
let
fileManager
=
FileManager
.
default
// Check whether a zip file exists at path.
guard
let
path
=
zipFilePath
.
path
,
destination
.
path
!=
nil
else
{
throw
ZipError
.
fileNotFound
}
let
path
=
zipFilePath
.
path
if
fileManager
.
fileExists
(
atPath
:
path
)
==
false
||
fileExtensionIsInvalid
(
zipFilePath
.
pathExtension
)
{
throw
ZipError
.
fileNotFound
}
...
...
@@ -121,7 +120,8 @@ public class Zip {
}
currentPosition
+=
Double
(
fileInfo
.
compressed_size
)
let
fileNameSize
=
Int
(
fileInfo
.
size_filename
)
+
1
let
fileName
=
UnsafeMutablePointer
<
CChar
>
(
allocatingCapacity
:
fileNameSize
)
//let fileName = UnsafeMutablePointer<CChar>(allocatingCapacity: fileNameSize)
let
fileName
=
UnsafeMutablePointer
<
CChar
>.
allocate
(
capacity
:
fileNameSize
)
unzGetCurrentFileInfo64
(
zip
,
&
fileInfo
,
fileName
,
UInt
(
fileNameSize
),
nil
,
0
,
nil
,
0
)
fileName
[
Int
(
fileInfo
.
size_filename
)]
=
0
...
...
@@ -140,9 +140,9 @@ public class Zip {
if
pathString
.
rangeOfCharacter
(
from
:
CharacterSet
(
charactersIn
:
"/
\\
"
))
!=
nil
{
pathString
=
pathString
.
replacingOccurrences
(
of
:
"
\\
"
,
with
:
"/"
)
}
guard
let
fullPath
=
try!
destination
.
appendingPathComponent
(
pathString
)
.
path
else
{
throw
ZipError
.
unzipFail
}
let
fullPath
=
destination
.
appendingPathComponent
(
pathString
)
.
path
let
creationDate
=
Date
()
let
directoryAttributes
=
[
FileAttributeKey
.
creationDate
.
rawValue
:
creationDate
,
FileAttributeKey
.
modificationDate
.
rawValue
:
creationDate
]
...
...
@@ -215,9 +215,7 @@ public class Zip {
let
fileManager
=
FileManager
.
default
// Check whether a zip file exists at path.
guard
let
destinationPath
=
zipFilePath
.
path
else
{
throw
ZipError
.
fileNotFound
}
let
destinationPath
=
zipFilePath
.
path
// Process zip paths
let
processedPaths
=
ZipUtilities
()
.
processZipPaths
(
paths
)
...
...
@@ -252,7 +250,7 @@ public class Zip {
let
filePath
=
path
.
filePath
()
var
isDirectory
:
ObjCBool
=
false
fileManager
.
fileExists
(
atPath
:
filePath
,
isDirectory
:
&
isDirectory
)
if
!
isDirectory
{
if
!
isDirectory
.
boolValue
{
let
input
=
fopen
(
filePath
,
"r"
)
if
input
==
nil
{
throw
ZipError
.
zipFail
...
...
@@ -262,7 +260,7 @@ public class Zip {
do
{
let
fileAttributes
=
try
fileManager
.
attributesOfItem
(
atPath
:
filePath
)
if
let
fileDate
=
fileAttributes
[
FileAttributeKey
.
modificationDate
]
as?
Date
{
let
components
=
Calendar
.
current
.
c
omponents
([
.
year
,
.
month
,
.
day
,
.
hour
,
.
minute
,
.
second
],
from
:
fileDate
)
let
components
=
Calendar
.
current
.
dateC
omponents
([
.
year
,
.
month
,
.
day
,
.
hour
,
.
minute
,
.
second
],
from
:
fileDate
)
zipInfo
.
tmz_date
.
tm_sec
=
UInt32
(
components
.
second
!
)
zipInfo
.
tmz_date
.
tm_min
=
UInt32
(
components
.
minute
!
)
zipInfo
.
tmz_date
.
tm_hour
=
UInt32
(
components
.
hour
!
)
...
...
Zip/ZipUtilities.swift
View file @
c8d9230b
...
...
@@ -21,12 +21,7 @@ internal class ZipUtilities {
let
fileName
:
String
?
func
filePath
()
->
String
{
if
let
filePath
=
filePathURL
.
path
{
return
filePath
}
else
{
return
String
()
}
return
filePathURL
.
path
}
}
...
...
@@ -42,12 +37,10 @@ internal class ZipUtilities {
internal
func
processZipPaths
(
_
paths
:
[
URL
])
->
[
ProcessedFilePath
]{
var
processedFilePaths
=
[
ProcessedFilePath
]()
for
path
in
paths
{
guard
let
filePath
=
path
.
path
else
{
continue
}
let
filePath
=
path
.
path
var
isDirectory
:
ObjCBool
=
false
fileManager
.
fileExists
(
atPath
:
filePath
,
isDirectory
:
&
isDirectory
)
if
!
isDirectory
{
if
!
isDirectory
.
boolValue
{
let
processedPath
=
ProcessedFilePath
(
filePathURL
:
path
,
fileName
:
path
.
lastPathComponent
)
processedFilePaths
.
append
(
processedPath
)
}
...
...
@@ -69,15 +62,16 @@ internal class ZipUtilities {
*/
internal
func
expandDirectoryFilePath
(
_
directory
:
URL
)
->
[
ProcessedFilePath
]
{
var
processedFilePaths
=
[
ProcessedFilePath
]()
if
let
directoryPath
=
directory
.
path
,
let
enumerator
=
fileManager
.
enumerator
(
atPath
:
directoryPath
)
{
let
directoryPath
=
directory
.
path
if
let
enumerator
=
fileManager
.
enumerator
(
atPath
:
directoryPath
)
{
while
let
filePathComponent
=
enumerator
.
nextObject
()
as?
String
{
let
path
=
try!
directory
.
appendingPathComponent
(
filePathComponent
)
guard
let
filePath
=
path
.
path
,
let
directoryName
=
directory
.
lastPathComponent
else
{
continue
}
let
path
=
directory
.
appendingPathComponent
(
filePathComponent
)
let
filePath
=
path
.
path
let
directoryName
=
directory
.
lastPathComponent
var
isDirectory
:
ObjCBool
=
false
fileManager
.
fileExists
(
atPath
:
filePath
,
isDirectory
:
&
isDirectory
)
if
!
isDirectory
{
if
!
isDirectory
.
boolValue
{
let
fileName
=
(
directoryName
as
NSString
)
.
appendingPathComponent
(
filePathComponent
)
let
processedPath
=
ProcessedFilePath
(
filePathURL
:
path
,
fileName
:
fileName
)
processedFilePaths
.
append
(
processedPath
)
...
...
ZipTests/ZipTests.swift
View file @
c8d9230b
...
...
@@ -21,10 +21,10 @@ class ZipTests: XCTestCase {
func
testQuickUnzip
()
{
do
{
let
filePath
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
ForResource
(
"bb8"
,
withExtension
:
"zip"
)
!
let
filePath
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
(
forResource
:
"bb8"
,
withExtension
:
"zip"
)
!
let
destinationURL
=
try
Zip
.
quickUnzipFile
(
filePath
)
let
fileManager
=
FileManager
.
default
XCTAssertTrue
(
fileManager
.
fileExists
(
atPath
:
destinationURL
.
path
!
))
XCTAssertTrue
(
fileManager
.
fileExists
(
atPath
:
destinationURL
.
path
))
}
catch
{
XCTFail
()
...
...
@@ -37,7 +37,7 @@ class ZipTests: XCTestCase {
let
filePath
=
NSURL
(
string
:
"
\(
filePathURL
!
)
/bb9.zip"
)
let
destinationURL
=
try
Zip
.
quickUnzipFile
(
filePath
!
as
URL
)
let
fileManager
=
FileManager
.
default
XCTAssertFalse
(
fileManager
.
fileExists
(
atPath
:
destinationURL
.
path
!
))
XCTAssertFalse
(
fileManager
.
fileExists
(
atPath
:
destinationURL
.
path
))
}
catch
{
XCTAssert
(
true
)
...
...
@@ -46,10 +46,10 @@ class ZipTests: XCTestCase {
func
testQuickUnzipNonZipPath
()
{
do
{
let
filePath
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
ForResource
(
"3crBXeO"
,
withExtension
:
"gif"
)
!
let
filePath
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
(
forResource
:
"3crBXeO"
,
withExtension
:
"gif"
)
!
let
destinationURL
=
try
Zip
.
quickUnzipFile
(
filePath
)
let
fileManager
=
FileManager
.
default
XCTAssertFalse
(
fileManager
.
fileExists
(
atPath
:
destinationURL
.
path
!
))
XCTAssertFalse
(
fileManager
.
fileExists
(
atPath
:
destinationURL
.
path
))
}
catch
{
XCTAssert
(
true
)
...
...
@@ -58,8 +58,8 @@ class ZipTests: XCTestCase {
func
testQuickUnzipProgress
()
{
do
{
let
filePath
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
ForResource
(
"bb8"
,
withExtension
:
"zip"
)
!
try
Zip
.
quickUnzipFile
(
filePath
,
progress
:
{
(
progress
)
->
()
in
let
filePath
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
(
forResource
:
"bb8"
,
withExtension
:
"zip"
)
!
_
=
try
Zip
.
quickUnzipFile
(
filePath
,
progress
:
{
(
progress
)
->
()
in
XCTAssert
(
true
)
})
}
...
...
@@ -73,7 +73,7 @@ class ZipTests: XCTestCase {
let
filePath
=
NSURL
(
string
:
"http://www.google.com/google.zip"
)
!
let
destinationURL
=
try
Zip
.
quickUnzipFile
(
filePath
as
URL
)
let
fileManager
=
FileManager
.
default
XCTAssertFalse
(
fileManager
.
fileExists
(
atPath
:
destinationURL
.
path
!
))
XCTAssertFalse
(
fileManager
.
fileExists
(
atPath
:
destinationURL
.
path
))
}
catch
{
XCTAssert
(
true
)
...
...
@@ -82,8 +82,8 @@ class ZipTests: XCTestCase {
func
testUnzip
()
{
do
{
let
filePath
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
ForResource
(
"bb8"
,
withExtension
:
"zip"
)
!
let
documentsFolder
=
FileManager
.
default
.
urls
ForDirectory
(
.
documentDirectory
,
inDomains
:
.
userDomainMask
)[
0
]
as
NSURL
let
filePath
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
(
forResource
:
"bb8"
,
withExtension
:
"zip"
)
!
let
documentsFolder
=
FileManager
.
default
.
urls
(
for
:
.
documentDirectory
,
in
:
.
userDomainMask
)[
0
]
as
NSURL
try
Zip
.
unzipFile
(
filePath
,
destination
:
documentsFolder
as
URL
,
overwrite
:
true
,
password
:
"password"
,
progress
:
{
(
progress
)
->
()
in
print
(
progress
)
...
...
@@ -102,8 +102,8 @@ class ZipTests: XCTestCase {
let
progress
=
Progress
()
progress
.
totalUnitCount
=
1
let
filePath
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
ForResource
(
"bb8"
,
withExtension
:
"zip"
)
!
let
documentsFolder
=
FileManager
.
default
.
urls
ForDirectory
(
.
documentDirectory
,
inDomains
:
.
userDomainMask
)[
0
]
as
NSURL
let
filePath
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
(
forResource
:
"bb8"
,
withExtension
:
"zip"
)
!
let
documentsFolder
=
FileManager
.
default
.
urls
(
for
:
.
documentDirectory
,
in
:
.
userDomainMask
)[
0
]
as
NSURL
progress
.
becomeCurrent
(
withPendingUnitCount
:
1
)
try
Zip
.
unzipFile
(
filePath
,
destination
:
documentsFolder
as
URL
,
overwrite
:
true
,
password
:
"password"
,
progress
:
nil
)
...
...
@@ -122,9 +122,9 @@ class ZipTests: XCTestCase {
let
progress
=
Progress
()
progress
.
totalUnitCount
=
1
let
imageURL1
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
ForResource
(
"3crBXeO"
,
withExtension
:
"gif"
)
!
let
imageURL2
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
ForResource
(
"kYkLkPf"
,
withExtension
:
"gif"
)
!
let
documentsFolder
=
FileManager
.
default
.
urls
ForDirectory
(
.
documentDirectory
,
inDomains
:
.
userDomainMask
)[
0
]
as
NSURL
let
imageURL1
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
(
forResource
:
"3crBXeO"
,
withExtension
:
"gif"
)
!
let
imageURL2
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
(
forResource
:
"kYkLkPf"
,
withExtension
:
"gif"
)
!
let
documentsFolder
=
FileManager
.
default
.
urls
(
for
:
.
documentDirectory
,
in
:
.
userDomainMask
)[
0
]
as
NSURL
let
zipFilePath
=
documentsFolder
.
appendingPathComponent
(
"archive.zip"
)
progress
.
becomeCurrent
(
withPendingUnitCount
:
1
)
...
...
@@ -141,11 +141,11 @@ class ZipTests: XCTestCase {
func
testQuickZip
()
{
do
{
let
imageURL1
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
ForResource
(
"3crBXeO"
,
withExtension
:
"gif"
)
!
let
imageURL2
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
ForResource
(
"kYkLkPf"
,
withExtension
:
"gif"
)
!
let
imageURL1
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
(
forResource
:
"3crBXeO"
,
withExtension
:
"gif"
)
!
let
imageURL2
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
(
forResource
:
"kYkLkPf"
,
withExtension
:
"gif"
)
!
let
destinationURL
=
try
Zip
.
quickZipFiles
([
imageURL1
,
imageURL2
],
fileName
:
"archive"
)
let
fileManager
=
FileManager
.
default
XCTAssertTrue
(
fileManager
.
fileExists
(
atPath
:
destinationURL
.
path
!
))
XCTAssertTrue
(
fileManager
.
fileExists
(
atPath
:
destinationURL
.
path
))
}
catch
{
XCTFail
()
...
...
@@ -155,19 +155,19 @@ class ZipTests: XCTestCase {
func
testQuickZipFolder
()
{
do
{
let
fileManager
=
FileManager
.
default
let
imageURL1
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
ForResource
(
"3crBXeO"
,
withExtension
:
"gif"
)
!
let
imageURL2
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
ForResource
(
"kYkLkPf"
,
withExtension
:
"gif"
)
!
let
folderURL
=
try
Bundle
(
for
:
ZipTests
.
self
)
.
bundleURL
.
appendingPathComponent
(
"Directory"
)
let
targetImageURL1
=
try
folderURL
.
appendingPathComponent
(
"3crBXeO.gif"
)
let
targetImageURL2
=
try
folderURL
.
appendingPathComponent
(
"kYkLkPf.gif"
)
if
fileManager
.
fileExists
(
atPath
:
folderURL
.
path
!
)
{
let
imageURL1
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
(
forResource
:
"3crBXeO"
,
withExtension
:
"gif"
)
!
let
imageURL2
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
(
forResource
:
"kYkLkPf"
,
withExtension
:
"gif"
)
!
let
folderURL
=
Bundle
(
for
:
ZipTests
.
self
)
.
bundleURL
.
appendingPathComponent
(
"Directory"
)
let
targetImageURL1
=
folderURL
.
appendingPathComponent
(
"3crBXeO.gif"
)
let
targetImageURL2
=
folderURL
.
appendingPathComponent
(
"kYkLkPf.gif"
)
if
fileManager
.
fileExists
(
atPath
:
folderURL
.
path
)
{
try
fileManager
.
removeItem
(
at
:
folderURL
)
}
try
fileManager
.
createDirectory
(
at
:
folderURL
,
withIntermediateDirectories
:
false
,
attributes
:
nil
)
try
fileManager
.
copyItem
(
at
:
imageURL1
,
to
:
targetImageURL1
)
try
fileManager
.
copyItem
(
at
:
imageURL2
,
to
:
targetImageURL2
)
let
destinationURL
=
try
Zip
.
quickZipFiles
([
folderURL
],
fileName
:
"directory"
)
XCTAssertTrue
(
fileManager
.
fileExists
(
atPath
:
destinationURL
.
path
!
))
XCTAssertTrue
(
fileManager
.
fileExists
(
atPath
:
destinationURL
.
path
))
}
catch
{
XCTFail
()
...
...
@@ -177,15 +177,15 @@ class ZipTests: XCTestCase {
func
testZip
()
{
do
{
let
imageURL1
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
ForResource
(
"3crBXeO"
,
withExtension
:
"gif"
)
!
let
imageURL2
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
ForResource
(
"kYkLkPf"
,
withExtension
:
"gif"
)
!
let
documentsFolder
=
FileManager
.
default
.
urls
ForDirectory
(
.
documentDirectory
,
inDomains
:
.
userDomainMask
)[
0
]
as
NSURL
let
imageURL1
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
(
forResource
:
"3crBXeO"
,
withExtension
:
"gif"
)
!
let
imageURL2
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
(
forResource
:
"kYkLkPf"
,
withExtension
:
"gif"
)
!
let
documentsFolder
=
FileManager
.
default
.
urls
(
for
:
.
documentDirectory
,
in
:
.
userDomainMask
)[
0
]
as
NSURL
let
zipFilePath
=
documentsFolder
.
appendingPathComponent
(
"archive.zip"
)
try
Zip
.
zipFiles
([
imageURL1
,
imageURL2
],
zipFilePath
:
zipFilePath
!
,
password
:
nil
,
progress
:
{
(
progress
)
->
()
in
print
(
progress
)
})
let
fileManager
=
FileManager
.
default
XCTAssertTrue
(
fileManager
.
fileExists
(
atPath
:(
zipFilePath
?
.
path
!
)
!
))
XCTAssertTrue
(
fileManager
.
fileExists
(
atPath
:(
zipFilePath
?
.
path
)
!
))
}
catch
{
XCTFail
()
...
...
@@ -194,23 +194,23 @@ class ZipTests: XCTestCase {
func
testZipUnzipPassword
()
{
do
{
let
imageURL1
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
ForResource
(
"3crBXeO"
,
withExtension
:
"gif"
)
!
let
imageURL2
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
ForResource
(
"kYkLkPf"
,
withExtension
:
"gif"
)
!
let
documentsFolder
=
FileManager
.
default
.
urls
ForDirectory
(
.
documentDirectory
,
inDomains
:
.
userDomainMask
)[
0
]
as
NSURL
let
imageURL1
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
(
forResource
:
"3crBXeO"
,
withExtension
:
"gif"
)
!
let
imageURL2
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
(
forResource
:
"kYkLkPf"
,
withExtension
:
"gif"
)
!
let
documentsFolder
=
FileManager
.
default
.
urls
(
for
:
.
documentDirectory
,
in
:
.
userDomainMask
)[
0
]
as
NSURL
let
zipFilePath
=
documentsFolder
.
appendingPathComponent
(
"archive.zip"
)
try
Zip
.
zipFiles
([
imageURL1
,
imageURL2
],
zipFilePath
:
zipFilePath
!
,
password
:
"password"
,
progress
:
{
(
progress
)
->
()
in
print
(
progress
)
})
let
fileManager
=
FileManager
.
default
XCTAssertTrue
(
fileManager
.
fileExists
(
atPath
:(
zipFilePath
?
.
path
!
)
!
))
XCTAssertTrue
(
fileManager
.
fileExists
(
atPath
:(
zipFilePath
?
.
path
)
!
))
guard
let
fileExtension
=
zipFilePath
?
.
pathExtension
,
let
fileName
=
zipFilePath
?
.
lastPathComponent
else
{
throw
ZipError
.
unzipFail
}
let
directoryName
=
fileName
.
replacingOccurrences
(
of
:
".
\(
fileExtension
)
"
,
with
:
""
)
let
documentsUrl
=
fileManager
.
urls
ForDirectory
(
.
documentDirectory
,
inDomains
:
.
userDomainMask
)[
0
]
as
NSURL
let
documentsUrl
=
fileManager
.
urls
(
for
:
.
documentDirectory
,
in
:
.
userDomainMask
)[
0
]
as
NSURL
let
destinationUrl
=
documentsUrl
.
appendingPathComponent
(
directoryName
,
isDirectory
:
true
)
try
Zip
.
unzipFile
(
zipFilePath
!
,
destination
:
destinationUrl
!
,
overwrite
:
true
,
password
:
"password"
,
progress
:
nil
)
XCTAssertTrue
(
fileManager
.
fileExists
(
atPath
:(
destinationUrl
?
.
path
!
)
!
))
XCTAssertTrue
(
fileManager
.
fileExists
(
atPath
:(
destinationUrl
?
.
path
)
!
))
}
catch
{
XCTFail
()
...
...
@@ -220,15 +220,15 @@ class ZipTests: XCTestCase {
func
testQuickUnzipSubDir
()
{
do
{
let
bookURL
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
ForResource
(
"bb8"
,
withExtension
:
"zip"
)
!
let
bookURL
=
Bundle
(
for
:
ZipTests
.
self
)
.
url
(
forResource
:
"bb8"
,
withExtension
:
"zip"
)
!
let
unzipDestination
=
try
Zip
.
quickUnzipFile
(
bookURL
)
let
fileManager
=
FileManager
.
default
let
subDir
=
try
unzipDestination
.
appendingPathComponent
(
"subDir"
)
let
imageURL
=
try
subDir
.
appendingPathComponent
(
"r2W9yu9"
)
.
appendingPathExtension
(
"gif"
)
let
subDir
=
unzipDestination
.
appendingPathComponent
(
"subDir"
)
let
imageURL
=
subDir
.
appendingPathComponent
(
"r2W9yu9"
)
.
appendingPathExtension
(
"gif"
)
XCTAssertTrue
(
fileManager
.
fileExists
(
atPath
:
unzipDestination
.
path
!
))
XCTAssertTrue
(
fileManager
.
fileExists
(
atPath
:
subDir
.
path
!
))
XCTAssertTrue
(
fileManager
.
fileExists
(
atPath
:
imageURL
.
path
!
))
XCTAssertTrue
(
fileManager
.
fileExists
(
atPath
:
unzipDestination
.
path
))
XCTAssertTrue
(
fileManager
.
fileExists
(
atPath
:
subDir
.
path
))
XCTAssertTrue
(
fileManager
.
fileExists
(
atPath
:
imageURL
.
path
))
}
catch
{
XCTFail
()
}
...
...
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