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
Expand all
Show 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
This diff is collapsed.
Click to expand it.
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