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
3825c68f
Commit
3825c68f
authored
Jan 13, 2016
by
Roy Marmelstein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Successful unzipping buffer
parent
3b5bfe33
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
111 deletions
+75
-111
Zip.xcodeproj/project.pbxproj
Zip.xcodeproj/project.pbxproj
+0
-4
Zip/Zip.swift
Zip/Zip.swift
+74
-69
Zip/ZipHelpers.swift
Zip/ZipHelpers.swift
+0
-37
examples/Sample/Sample/ViewController.swift
examples/Sample/Sample/ViewController.swift
+1
-1
No files found.
Zip.xcodeproj/project.pbxproj
View file @
3825c68f
...
...
@@ -7,7 +7,6 @@
objects
=
{
/* Begin PBXBuildFile section */
3430F5D61C45B7FB007473A6
/* ZipHelpers.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
3430F5D51C45B7FB007473A6
/* ZipHelpers.swift */
;
};
3430F6201C45C805007473A6
/* libz.tbd in Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
3430F61F1C45C805007473A6
/* libz.tbd */
;
};
3430F62D1C45C851007473A6
/* crypt.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
3430F6221C45C851007473A6
/* crypt.h */
;
};
3430F62E1C45C851007473A6
/* include.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
3430F6231C45C851007473A6
/* include.h */
;
};
...
...
@@ -58,7 +57,6 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
3430F5D51C45B7FB007473A6
/* ZipHelpers.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ZipHelpers.swift
;
sourceTree
=
"<group>"
;
};
3430F61F1C45C805007473A6
/* libz.tbd */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
"sourcecode.text-based-dylib-definition"
;
name
=
libz.tbd
;
path
=
usr/lib/libz.tbd
;
sourceTree
=
SDKROOT
;
};
3430F6221C45C851007473A6
/* crypt.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
crypt.h
;
sourceTree
=
"<group>"
;
};
3430F6231C45C851007473A6
/* include.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
include.h
;
sourceTree
=
"<group>"
;
};
...
...
@@ -197,7 +195,6 @@
347E3B1E1C1E1CB500A11FD3
/* libz.1.2.5.tbd */
,
347E3A771C1DFFB500A11FD3
/* Zip.h */
,
347E3A791C1DFFB500A11FD3
/* Info.plist */
,
3430F5D51C45B7FB007473A6
/* ZipHelpers.swift */
,
347E3AD71C1E04C900A11FD3
/* Zip.swift */
,
);
path
=
Zip
;
...
...
@@ -351,7 +348,6 @@
3430F6351C45C851007473A6
/* zip.c in Sources */
,
3430F6311C45C851007473A6
/* mztools.c in Sources */
,
3430F6511C45C8AD007473A6
/* aescrypt.c in Sources */
,
3430F5D61C45B7FB007473A6
/* ZipHelpers.swift in Sources */
,
3430F6601C45C8AD007473A6
/* pwd2key.c in Sources */
,
3430F65A1C45C8AD007473A6
/* fileenc.c in Sources */
,
);
...
...
Zip/Zip.swift
View file @
3825c68f
...
...
@@ -29,7 +29,7 @@ public class Zip {
}
public
func
unzipFile
(
path
:
String
,
destination
:
String
,
overwrite
:
Bool
,
password
:
String
?
)
throws
{
public
func
unzipFile
(
path
:
String
,
destination
:
String
,
overwrite
:
Bool
)
throws
{
let
zip
=
unzOpen
(
path
)
var
currentPosition
=
0.0
var
globalInfo
:
unz_global_info
=
unz_global_info
(
number_entry
:
0
,
number_disk_with_CD
:
0
,
size_comment
:
0
)
...
...
@@ -44,12 +44,8 @@ public class Zip {
let
bufferSize
=
4096
var
buffer
=
Array
<
CUnsignedChar
>
(
count
:
bufferSize
,
repeatedValue
:
0
)
let
fileManager
=
NSFileManager
.
defaultManager
()
if
let
password
=
password
where
password
.
characters
.
count
>
0
{
ret
=
unzOpenCurrentFilePassword
(
zip
,
password
.
cStringUsingEncoding
(
NSASCIIStringEncoding
)
!
)
}
else
{
repeat
{
ret
=
unzOpenCurrentFile
(
zip
)
}
if
ret
!=
UNZ_OK
{
throw
ZipError
.
UnzipError
}
...
...
@@ -100,12 +96,19 @@ public class Zip {
var
filePointer
:
UnsafeMutablePointer
<
FILE
>
filePointer
=
fopen
(
fullPath
,
"wb"
)
while
filePointer
!=
nil
{
let
readBytes
=
unzReadCurrentFile
(
zip
,
&
buffer
,
4096
)
if
readBytes
>
0
{
fwrite
(
buffer
,
Int
(
readBytes
),
1
,
filePointer
)
}
else
{
break
}
}
if
filePointer
!=
nil
{
if
((
fullPath
as
NSString
)
.
pathExtension
.
lowercaseString
==
"zip"
)
{
// nested zip
try
unzipFile
(
fullPath
,
destination
:
(
fullPath
as
NSString
)
.
stringByDeletingLastPathComponent
,
overwrite
:
overwrite
,
password
:
password
)
try
unzipFile
(
fullPath
,
destination
:
(
fullPath
as
NSString
)
.
stringByDeletingLastPathComponent
,
overwrite
:
overwrite
)
}
}
fclose
(
filePointer
)
...
...
@@ -114,7 +117,9 @@ public class Zip {
throw
ZipError
.
UnzipError
}
ret
=
unzGoToNextFile
(
zip
)
currentPosition
++
}
while
(
ret
==
UNZ_OK
&&
ret
!=
UNZ_END_OF_LIST_OF_FILE
)
}
...
...
Zip/ZipHelpers.swift
deleted
100644 → 0
View file @
3b5bfe33
//
// ZipHelpers.swift
// Zip
//
// Created by Roy Marmelstein on 12/01/2016.
// Copyright © 2016 Roy Marmelstein. All rights reserved.
//
import
Foundation
public
enum
FopenMode
:
String
{
case
Read
=
"r"
case
Write
=
"w"
}
public
func
ZIPFopen
(
path
:
String
...
,
mode
:
FopenMode
=
.
Read
)
throws
->
UnsafeMutablePointer
<
FILE
>
{
let
path
=
joinPathComponents
(
path
)
let
f
=
fopen
(
path
,
mode
.
rawValue
)
guard
f
!=
nil
else
{
throw
ZipError
.
FileError
}
return
f
}
/**
Joins path components, unless a component is an absolute
path, in which case it discards all previous path components.
*/
func
joinPathComponents
(
join
:
[
String
])
->
String
{
guard
join
.
count
>
0
else
{
return
""
}
return
join
.
dropFirst
(
1
)
.
reduce
(
join
[
0
])
{
if
$1
.
hasPrefix
(
"/"
)
{
return
$1
}
else
{
return
$0
+
"/"
+
$1
}
}
}
\ No newline at end of file
examples/Sample/Sample/ViewController.swift
View file @
3825c68f
...
...
@@ -18,7 +18,7 @@ class ViewController: UIViewController {
let
fileAbsoluteUrl
=
NSBundle
.
mainBundle
()
.
pathForResource
(
"master"
,
ofType
:
"zip"
)
let
fileManager
=
NSFileManager
.
defaultManager
()
let
fileExists
=
fileManager
.
fileExistsAtPath
(
fileAbsoluteUrl
!
)
try
Zip
()
.
unzipFile
(
fileAbsoluteUrl
!
,
destination
:
destinationPath
,
overwrite
:
true
,
password
:
nil
)
try
Zip
()
.
unzipFile
(
fileAbsoluteUrl
!
,
destination
:
destinationPath
,
overwrite
:
true
)
}
catch
{
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