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
63cdd914
Commit
63cdd914
authored
9 years ago
by
Roy Marmelstein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved handling of directories inside a zip file
parent
b5a63a0c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
43 deletions
+47
-43
Zip/Zip.swift
Zip/Zip.swift
+47
-43
No files found.
Zip/Zip.swift
View file @
63cdd914
...
...
@@ -215,52 +215,56 @@ public class Zip {
guard
let
filePath
=
path
.
path
else
{
throw
ZipError
.
ZipFail
}
let
input
=
fopen
(
filePath
,
"r"
)
if
input
==
nil
{
throw
ZipError
.
ZipFail
}
let
fileName
=
path
.
lastPathComponent
var
zipInfo
:
zip_fileinfo
=
zip_fileinfo
(
tmz_date
:
tm_zip
(
tm_sec
:
0
,
tm_min
:
0
,
tm_hour
:
0
,
tm_mday
:
0
,
tm_mon
:
0
,
tm_year
:
0
),
dosDate
:
0
,
internal_fa
:
0
,
external_fa
:
0
)
do
{
let
fileAttributes
=
try
fileManager
.
attributesOfItemAtPath
(
filePath
)
if
let
fileDate
=
fileAttributes
[
NSFileModificationDate
]
as?
NSDate
{
let
components
=
NSCalendar
.
currentCalendar
()
.
components
([
.
Year
,
.
Month
,
.
Day
,
.
Hour
,
.
Minute
,
.
Second
],
fromDate
:
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
)
zipInfo
.
tmz_date
.
tm_mday
=
UInt32
(
components
.
day
)
zipInfo
.
tmz_date
.
tm_mon
=
UInt32
(
components
.
month
)
-
1
zipInfo
.
tmz_date
.
tm_year
=
UInt32
(
components
.
year
)
var
isDirectory
:
ObjCBool
=
false
fileManager
.
fileExistsAtPath
(
filePath
,
isDirectory
:
&
isDirectory
)
if
!
isDirectory
{
let
input
=
fopen
(
filePath
,
"r"
)
if
input
==
nil
{
throw
ZipError
.
ZipFail
}
if
let
fileSize
=
fileAttributes
[
NSFileSize
]
as?
Double
{
currentPosition
+=
fileSize
let
fileName
=
path
.
lastPathComponent
var
zipInfo
:
zip_fileinfo
=
zip_fileinfo
(
tmz_date
:
tm_zip
(
tm_sec
:
0
,
tm_min
:
0
,
tm_hour
:
0
,
tm_mday
:
0
,
tm_mon
:
0
,
tm_year
:
0
),
dosDate
:
0
,
internal_fa
:
0
,
external_fa
:
0
)
do
{
let
fileAttributes
=
try
fileManager
.
attributesOfItemAtPath
(
filePath
)
if
let
fileDate
=
fileAttributes
[
NSFileModificationDate
]
as?
NSDate
{
let
components
=
NSCalendar
.
currentCalendar
()
.
components
([
.
Year
,
.
Month
,
.
Day
,
.
Hour
,
.
Minute
,
.
Second
],
fromDate
:
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
)
zipInfo
.
tmz_date
.
tm_mday
=
UInt32
(
components
.
day
)
zipInfo
.
tmz_date
.
tm_mon
=
UInt32
(
components
.
month
)
-
1
zipInfo
.
tmz_date
.
tm_year
=
UInt32
(
components
.
year
)
}
if
let
fileSize
=
fileAttributes
[
NSFileSize
]
as?
Double
{
currentPosition
+=
fileSize
}
}
catch
{}
let
buffer
=
malloc
(
chunkSize
)
if
let
password
=
password
,
let
fileName
=
fileName
{
zipOpenNewFileInZip3
(
zip
,
fileName
,
&
zipInfo
,
nil
,
0
,
nil
,
0
,
nil
,
Z_DEFLATED
,
Z_DEFAULT_COMPRESSION
,
0
,
-
MAX_WBITS
,
DEF_MEM_LEVEL
,
Z_DEFAULT_STRATEGY
,
password
,
0
)
}
else
if
let
fileName
=
fileName
{
zipOpenNewFileInZip3
(
zip
,
fileName
,
&
zipInfo
,
nil
,
0
,
nil
,
0
,
nil
,
Z_DEFLATED
,
Z_DEFAULT_COMPRESSION
,
0
,
-
MAX_WBITS
,
DEF_MEM_LEVEL
,
Z_DEFAULT_STRATEGY
,
nil
,
0
)
}
else
{
throw
ZipError
.
ZipFail
}
var
length
:
Int
=
0
while
(
feof
(
input
)
==
0
)
{
length
=
fread
(
buffer
,
1
,
chunkSize
,
input
)
zipWriteInFileInZip
(
zip
,
buffer
,
UInt32
(
length
))
}
// Update progress handler
if
let
progressHandler
=
progress
{
progressHandler
(
progress
:
(
currentPosition
/
totalSize
))
}
zipCloseFileInZip
(
zip
)
free
(
buffer
)
fclose
(
input
)
}
catch
{}
let
buffer
=
malloc
(
chunkSize
)
if
let
password
=
password
,
let
fileName
=
fileName
{
zipOpenNewFileInZip3
(
zip
,
fileName
,
&
zipInfo
,
nil
,
0
,
nil
,
0
,
nil
,
Z_DEFLATED
,
Z_DEFAULT_COMPRESSION
,
0
,
-
MAX_WBITS
,
DEF_MEM_LEVEL
,
Z_DEFAULT_STRATEGY
,
password
,
0
)
}
else
if
let
fileName
=
fileName
{
zipOpenNewFileInZip3
(
zip
,
fileName
,
&
zipInfo
,
nil
,
0
,
nil
,
0
,
nil
,
Z_DEFLATED
,
Z_DEFAULT_COMPRESSION
,
0
,
-
MAX_WBITS
,
DEF_MEM_LEVEL
,
Z_DEFAULT_STRATEGY
,
nil
,
0
)
}
else
{
throw
ZipError
.
ZipFail
}
var
length
:
Int
=
0
while
(
feof
(
input
)
==
0
)
{
length
=
fread
(
buffer
,
1
,
chunkSize
,
input
)
zipWriteInFileInZip
(
zip
,
buffer
,
UInt32
(
length
))
}
// Update progress handler
if
let
progressHandler
=
progress
{
progressHandler
(
progress
:
(
currentPosition
/
totalSize
))
}
zipCloseFileInZip
(
zip
)
free
(
buffer
)
fclose
(
input
)
}
zipClose
(
zip
,
nil
)
...
...
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