Comments (7)
+1 for eliminating the extension verifying. It is not necessary or a good reason to use the extension to determine whether the file can be opened or not. My situation is similar to @jwelton 's: a downloaded file by URLSession
gives a tmp
extension for now. I can add tmp
to the allowed list, but there is no guarantee the downloaded file would be always end with tmp
. Manually adding zip
suffix to the file name is quite unnature for an elegant API.
from zip.
Is it necessary to check if the file exists? Apple, in their documentation, recommends to try to open the file and to handle any errors that might occur gracefully.
NOTE
Attempting to predicate behavior based on the current state of the file system or a particular file on the file system is not recommended. Doing so can cause odd behavior or race conditions. Itโs far better to attempt an operation (such as loading a file or creating a directory), check for errors, and handle those errors gracefully than it is to try to figure out ahead of time whether the operation will succeed. For more information on file-system race conditions, see Race Conditions and Secure File Operations in Secure Coding Guide.
Source: NSFileManager fileExistsAtPath(_:)
from zip.
From what I understand, this will not be easy to implement. The NSFileManager does not recognize files that do not have an extension. (I've tried this and I'm getting false from fileExistsAtPath, when the file does exist). Perhaps your solution would be to explicitly set the extension, like you mentioned.
from zip.
This is true, however when bypassing validation, the following line was failing:
try fileManager.attributesOfItemAtPath(path)
from zip.
In my test it doesn't seem to fail. Am I missing something?
Test file /tmp/test0, created with:
mkfile -n 5m /tmp/test0
Swift code:
let fileManager = NSFileManager.defaultManager()
let attributes = try? fileManager.attributesOfItemAtPath("/tmp/test0")
print(attributes)
Output:
Optional([
"NSFileCreationDate": 2016-08-03 01:31:10 +0000,
"NSFileGroupOwnerAccountName": wheel,
"NSFileExtensionHidden": 0,
"NSFileSize": 5242880,
"NSFileGroupOwnerAccountID": 0,
"NSFileOwnerAccountID": 501,
"NSFilePosixPermissions": 384,
"NSFileType": NSFileTypeRegular,
"NSFileSystemFileNumber": 39560369,
"NSFileSystemNumber": 16777220,
"NSFileReferenceCount": 1,
"NSFileModificationDate": 2016-08-03 01:31:10 +0000
])
File size, creation and modification date etc. all seem to make sense.
It also works fine if the file without extension is in the app document directory.
from zip.
Just to let you know, I use your project and it's working well but having to add .zip
is unnatural.
There are multiple other file formats using zip compression, in my case mxl
: http://www.musicxml.com/tutorial/compressed-mxl-files/
from zip.
Tried the code by removing the validation, and has no issues with other extensions. Also this validation is case sensitive so if you need to add all the combinations zip
Zip
ZIP
etc making it extra annoying if you need to add others too.
from zip.
Related Issues (20)
- 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?
- Is it possible to unzip to memory directly without writing to a temp file?
- Privacy Manifest HOT 2
- Privacy Manifest HOT 4
- password does not work when trying to unzip file on MacBook
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.