Comments (11)
Finally I have solved the problem!
Just put #define HAVE_AES
into zip.c
file and copy aes libraries to the project, all things will be OK.
One thing I'm not clear that if I don't have #define HAVE_AES
, it will use DEFLATED compression method as default, isn't it? So why all of the unzip softwares can't even unzip it.
But anyway, the problem has been solved!
Thanks @mostafaberg and @marmelroy so much!
from zip.
Can you show a code snippet on how you create that ?
from zip.
I'm just use the latest version of this library, here is the zip method:
public class func zipFiles(paths: [URL], zipFilePath: URL, password: String?, compression: ZipCompression = .DefaultCompression, progress: ((_ progress: Double) -> ())?) throws {
// File manager
let fileManager = FileManager.default
// Check whether a zip file exists at path.
let destinationPath = zipFilePath.path
// Process zip paths
let processedPaths = ZipUtilities().processZipPaths(paths)
// Zip set up
let chunkSize: Int = 16384
// Progress handler set up
var currentPosition: Double = 0.0
var totalSize: Double = 0.0
// Get totalSize for progress handler
for path in processedPaths {
do {
let filePath = path.filePath()
let fileAttributes = try fileManager.attributesOfItem(atPath: filePath)
let fileSize = fileAttributes[FileAttributeKey.size] as? Double
if let fileSize = fileSize {
totalSize += fileSize
}
}
catch {}
}
let progressTracker = Progress(totalUnitCount: Int64(totalSize))
progressTracker.isCancellable = false
progressTracker.isPausable = false
progressTracker.kind = ProgressKind.file
// Begin Zipping
let zip = zipOpen(destinationPath, APPEND_STATUS_CREATE)
for path in processedPaths {
let filePath = path.filePath()
var isDirectory: ObjCBool = false
fileManager.fileExists(atPath: filePath, isDirectory: &isDirectory)
if !isDirectory.boolValue {
let input = fopen(filePath, "r")
if input == nil {
throw ZipError.zipFail
}
let fileName = path.fileName
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.attributesOfItem(atPath: filePath)
if let fileDate = fileAttributes[FileAttributeKey.modificationDate] as? Date {
let components = Calendar.current.dateComponents([.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!)
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[FileAttributeKey.size] 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, compression.minizipCompression, 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, compression.minizipCompression, 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((currentPosition/totalSize))
}
progressTracker.completedUnitCount = Int64(currentPosition)
zipCloseFileInZip(zip)
free(buffer)
fclose(input)
}
}
zipClose(zip, nil)
// Completed. Update progress handler.
if let progressHandler = progress{
progressHandler(1.0)
}
progressTracker.completedUnitCount = Int64(totalSize)
}
I don't know the problem is from above method or minizip's method.
Thanks you!
from zip.
Interesting, can you breakpoint and see what the value of password
is on this line ?
zipOpenNewFileInZip3(zip, fileName, &zipInfo, nil, 0, nil, 0, nil,Z_DEFLATED, compression.minizipCompression, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, password, 0)
from zip.
Yes I have, value of the password is exactly what it does when inputted.
When I zip it and then unzip it also using this library on iOS, it's run perfectly. The problem is only occurred on Windows with third-party unzip softwares.
from zip.
I see, well to me it seems like you're doing everything correctly and my initial guess is that something is wrong with Minizip, will need to verify that, if the issue has been resolved in another version of minizp it should probably be updated here
@marmelroy ?
from zip.
duplicate of #23, seems to be the same issue
from zip.
Thanks @mostafaberg and @dttrinh, indeed there seems to be an issue with Zip and password protection. Will investigate properly over the next few days...
from zip.
I am having the same problem, unable to unZip the file if I use a password. I added #define HAVE_AES to the top of the zip.c file, where can I get the aes libraries that are required? I have searched GitHub but can't find them.
from zip.
include "aes/aes.h"
include "aes/fileenc.h"
include "aes/prng.h"
include "aes/entropy.h"
They are missing ! =(
from zip.
@emericspiroux same issue here.
I added #define HAVE_AES to the top of the zip.c file, but compiler report 「'aes/aes.h' file not found」
from zip.
Related Issues (20)
- Missing folder inside zipped file
- 'ioapi.h' file not found in xcode 13.1
- Question
- Unzipping also returns unzipped url to a corrupted file in a __MACOSX directory
- Not able to use zip.xcframework HOT 7
- Special characters
- Error when use version 2.1.2 HOT 2
- Unable to zip file from URL HOT 1
- _
- missing symbol called - xcframework
- Can’t zip 4000 plus files HOT 1
- not work on Mac 13.4.1
- Security vulnerability in Zip package
- Please update deployment target to 11.0
- Path traversal vulnerability HOT 2
- VisionOS support
- Call to undeclared function 'ZOPENDISK64'; ISO C99 and later do not support implicit function declarations
- Apple privacy manifest file
- Has been killed by theoperating system because it is using too muchmemory. HOT 1
- Is this project not being maintained anymore?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zip.