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
639a0727
Commit
639a0727
authored
Jan 13, 2016
by
Roy Marmelstein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Destination as NSURL
parent
b48db457
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
15 deletions
+10
-15
Zip/Zip.swift
Zip/Zip.swift
+8
-8
examples/Sample/Sample/ViewController.swift
examples/Sample/Sample/ViewController.swift
+2
-7
No files found.
Zip/Zip.swift
View file @
639a0727
...
...
@@ -26,21 +26,22 @@ public class Zip {
public
init
()
{}
public
func
unzipFile
(
path
:
NSURL
,
destination
:
String
,
overwrite
:
Bool
,
password
:
String
?)
throws
{
public
func
unzipFile
(
path
:
NSURL
,
destination
:
NSURL
,
overwrite
:
Bool
,
password
:
String
?)
throws
{
// Check file exists at path.
let
fileManager
=
NSFileManager
.
defaultManager
()
if
fileManager
.
fileExistsAtPath
(
path
.
absoluteString
)
==
false
{
throw
ZipError
.
FileNotFound
}
let
zip
=
unzOpen64
(
path
.
absoluteString
)
// Begin unzipping
if
unzGoToFirstFile
(
zip
)
!=
UNZ_OK
{
throw
ZipError
.
UnzipError
}
// Unzip set up
var
ret
:
Int32
=
0
var
crc_ret
:
Int32
=
0
let
bufferSize
:
UInt32
=
4096
var
buffer
=
Array
<
CUnsignedChar
>
(
count
:
Int
(
bufferSize
),
repeatedValue
:
0
)
// Begin unzipping
let
zip
=
unzOpen64
(
path
.
absoluteString
)
if
unzGoToFirstFile
(
zip
)
!=
UNZ_OK
{
throw
ZipError
.
UnzipError
}
repeat
{
if
let
cPassword
=
password
?
.
cStringUsingEncoding
(
NSASCIIStringEncoding
)
{
ret
=
unzOpenCurrentFilePassword
(
zip
,
cPassword
)
...
...
@@ -65,7 +66,6 @@ public class Zip {
}
unzGetCurrentFileInfo64
(
zip
,
&
fileInfo
,
fileName
,
UInt
(
fileNameSize
),
nil
,
0
,
nil
,
0
)
fileName
[
Int
(
fileInfo
.
size_filename
)]
=
0
var
strPath
=
String
.
fromCString
(
fileName
)
!
as
NSString
var
isDirectory
=
false
let
fileInfoSizeFileName
=
Int
(
fileInfo
.
size_filename
-
1
)
...
...
@@ -77,7 +77,7 @@ public class Zip {
if
(
strPath
.
rangeOfCharacterFromSet
(
NSCharacterSet
(
charactersInString
:
"/
\\
"
))
.
location
!=
NSNotFound
)
{
strPath
=
strPath
.
stringByReplacingOccurrencesOfString
(
"
\\
"
,
withString
:
"/"
)
}
let
fullPath
=
(
destination
as
NSString
)
.
stringByAppendingPathComponent
(
strPath
as
String
)
let
fullPath
=
destination
.
URLByAppendingPathComponent
(
strPath
as
String
)
.
path
!
let
creationDate
=
NSDate
()
let
directoryAttributes
=
[
NSFileCreationDate
:
creationDate
,
NSFileModificationDate
:
creationDate
]
if
isDirectory
{
...
...
examples/Sample/Sample/ViewController.swift
View file @
639a0727
...
...
@@ -31,7 +31,7 @@ class ViewController: UIViewController {
// Dispose of any resources that can be recreated.
}
func
tempUnzipPath
()
->
String
?
{
func
tempUnzipPath
()
->
NSURL
?
{
var
path
=
NSSearchPathForDirectoriesInDomains
(
.
CachesDirectory
,
.
UserDomainMask
,
true
)[
0
]
path
+=
"/
\(
NSUUID
()
.
UUIDString
)
"
let
url
=
NSURL
(
fileURLWithPath
:
path
)
...
...
@@ -41,12 +41,7 @@ class ViewController: UIViewController {
}
catch
{
return
nil
}
if
let
path
=
url
.
path
{
return
path
}
return
nil
return
url
}
}
...
...
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