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
a88d3d35
Commit
a88d3d35
authored
Jan 13, 2016
by
Roy Marmelstein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor clean up
parent
d0fc8183
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
9 deletions
+10
-9
Zip/Zip.swift
Zip/Zip.swift
+7
-7
examples/Sample/Sample/ViewController.swift
examples/Sample/Sample/ViewController.swift
+3
-2
No files found.
Zip/Zip.swift
View file @
a88d3d35
...
@@ -26,13 +26,13 @@ public class Zip {
...
@@ -26,13 +26,13 @@ public class Zip {
public
init
()
{}
public
init
()
{}
public
func
unzipFile
(
path
:
String
,
destination
:
String
,
overwrite
:
Bool
)
throws
{
public
func
unzipFile
(
path
:
NSURL
,
destination
:
String
,
overwrite
:
Bool
,
password
:
String
?
)
throws
{
// Check file exists at path.
// Check file exists at path.
let
fileManager
=
NSFileManager
.
defaultManager
()
let
fileManager
=
NSFileManager
.
defaultManager
()
if
fileManager
.
fileExistsAtPath
(
path
)
==
false
{
if
fileManager
.
fileExistsAtPath
(
path
.
absoluteString
)
==
false
{
throw
ZipError
.
FileNotFound
throw
ZipError
.
FileNotFound
}
}
let
zip
=
unzOpen
(
path
)
let
zip
=
unzOpen
64
(
path
.
absoluteString
)
// Begin unzipping
// Begin unzipping
if
unzGoToFirstFile
(
zip
)
!=
UNZ_OK
{
if
unzGoToFirstFile
(
zip
)
!=
UNZ_OK
{
throw
ZipError
.
UnzipError
throw
ZipError
.
UnzipError
...
@@ -46,9 +46,9 @@ public class Zip {
...
@@ -46,9 +46,9 @@ public class Zip {
if
ret
!=
UNZ_OK
{
if
ret
!=
UNZ_OK
{
throw
ZipError
.
UnzipError
throw
ZipError
.
UnzipError
}
}
var
fileInfo
=
unz_file_info
()
var
fileInfo
=
unz_file_info
64
()
memset
(
&
fileInfo
,
0
,
sizeof
(
unz_file_info
))
memset
(
&
fileInfo
,
0
,
sizeof
(
unz_file_info
))
ret
=
unzGetCurrentFileInfo
(
zip
,
&
fileInfo
,
nil
,
0
,
nil
,
0
,
nil
,
0
)
ret
=
unzGetCurrentFileInfo
64
(
zip
,
&
fileInfo
,
nil
,
0
,
nil
,
0
,
nil
,
0
)
if
ret
!=
UNZ_OK
{
if
ret
!=
UNZ_OK
{
unzCloseCurrentFile
(
zip
)
unzCloseCurrentFile
(
zip
)
throw
ZipError
.
UnzipError
throw
ZipError
.
UnzipError
...
@@ -58,7 +58,7 @@ public class Zip {
...
@@ -58,7 +58,7 @@ public class Zip {
if
fileName
==
nil
{
if
fileName
==
nil
{
throw
ZipError
.
UnzipError
throw
ZipError
.
UnzipError
}
}
unzGetCurrentFileInfo
(
zip
,
&
fileInfo
,
fileName
,
UInt
(
fileNameSize
),
nil
,
0
,
nil
,
0
)
unzGetCurrentFileInfo
64
(
zip
,
&
fileInfo
,
fileName
,
UInt
(
fileNameSize
),
nil
,
0
,
nil
,
0
)
fileName
[
Int
(
fileInfo
.
size_filename
)]
=
0
fileName
[
Int
(
fileInfo
.
size_filename
)]
=
0
var
strPath
=
String
.
fromCString
(
fileName
)
!
as
NSString
var
strPath
=
String
.
fromCString
(
fileName
)
!
as
NSString
...
@@ -70,7 +70,7 @@ public class Zip {
...
@@ -70,7 +70,7 @@ public class Zip {
free
(
fileName
)
free
(
fileName
)
if
(
strPath
.
rangeOfCharacterFromSet
(
NSCharacterSet
(
charactersInString
:
"/
\\
"
))
.
location
!=
NSNotFound
)
{
if
(
strPath
.
rangeOfCharacterFromSet
(
NSCharacterSet
(
charactersInString
:
"/
\\
"
))
.
location
!=
NSNotFound
)
{
strPath
=
strPath
.
stringByReplacingOccurrencesOfString
(
"
\\
"
,
withString
:
"/"
)
strPath
=
strPath
.
stringByReplacingOccurrencesOfString
(
"
\\
"
,
withString
:
"/"
)
}
}
let
fullPath
=
(
destination
as
NSString
)
.
stringByAppendingPathComponent
(
strPath
as
String
)
let
fullPath
=
(
destination
as
NSString
)
.
stringByAppendingPathComponent
(
strPath
as
String
)
let
creationDate
=
NSDate
()
let
creationDate
=
NSDate
()
...
...
examples/Sample/Sample/ViewController.swift
View file @
a88d3d35
...
@@ -15,9 +15,10 @@ class ViewController: UIViewController {
...
@@ -15,9 +15,10 @@ class ViewController: UIViewController {
super
.
viewDidLoad
()
super
.
viewDidLoad
()
do
{
do
{
let
destinationPath
=
tempUnzipPath
()
!
let
destinationPath
=
tempUnzipPath
()
!
let
fileAbsoluteUrl
=
NSBundle
.
mainBundle
()
.
pathForResource
(
"master"
,
ofType
:
"zip"
)
let
fileAbsolutePath
=
NSBundle
.
mainBundle
()
.
pathForResource
(
"master"
,
ofType
:
"zip"
)
let
fileAbsoluteURL
=
NSURL
(
string
:
fileAbsolutePath
!
)
!
print
(
destinationPath
)
print
(
destinationPath
)
try
Zip
()
.
unzipFile
(
fileAbsoluteU
rl
!
,
destination
:
destinationPath
,
overwrite
:
true
)
try
Zip
()
.
unzipFile
(
fileAbsoluteU
RL
,
destination
:
destinationPath
,
overwrite
:
true
,
password
:
nil
)
}
}
catch
{
catch
{
print
(
"oops"
)
print
(
"oops"
)
...
...
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