Closed arpitgarg23 closed 1 year ago
There is a known issue which prevents user zipping the single file on iOS with zip
method, as you can see here https://github.com/mockingbot/react-native-zip-archive/issues/230#issuecomment-770855411.
The current workaround is wrapping your file path with []
like [filePath]
, which would also is guaranteed to be working after fixing the original bug.
@ramos-lucas solution to wrap filePath in brackets fixed iOS problem where zip files were always empty ( 22 bytes long ).
await zip([filePath], zipPath)
Hopefully adding brackets does NOT break Android. I had been using this library for years. Both Android and IOS were zipping single files fine. Not sure why iOS started breaking?
I am having a similar issue, The thing is like this
tmp/A --x.bin --y.bin --a.json tmp/B --x.bin --y.bin --a.json
Then I zip: zip([tmp], 'tmp/out.zip']
the out.zip only contains a file called tmp with nothing
Do you have any idea about what is happening?
I am having a similar issue, The thing is like this
tmp/A --x.bin --y.bin --a.json tmp/B --x.bin --y.bin --a.json
Then I zip: zip([tmp], 'tmp/out.zip']
the out.zip only contains a file called tmp with nothing
Do you have any idea about what is happening?
I think it does not support zipping into the same folder as being zipped one.
I am having a similar issue, The thing is like this tmp/A --x.bin --y.bin --a.json tmp/B --x.bin --y.bin --a.json Then I zip: zip([tmp], 'tmp/out.zip'] the out.zip only contains a file called tmp with nothing Do you have any idea about what is happening?
I think it does not support zipping into the same folder as being zipped one.
so the example should be updated, but I tried with a different output directory and I have the same problem, when unzip I have a 128B empty Document
const targetPath = ${DocumentDirectoryPath}/myFile.zip
const sourcePath = DocumentDirectoryPath
zip(sourcePath, targetPath)
.then((path) => {
console.log(zip completed at ${path}
)
})
.catch((error) => {
console.error(error)
})
Now Im able to zip the files but iterating over all the folder to get all the files
->
tmp/A
--x.bin
--y.bin
--a.json
tmp/B
--x.bin
--y.bin
--a.json
-> [ A/x.bin, A/y.bin, A/a.json, B/x.bin, B/Y.bin, B/a.json ] and this creates a flat folder
OK, that seems an issue, could you share the folder you're trying to zip? So I can debug on it.
I ran into this again. I found code where I forgot to wrap filePath in brackets.
For the curious, the cause is the react-native-zip-archive index.js exports a single zip method, that uses the argument type to determine whether to call RNZipArchive.zipFiles or RNZipArchive.zipFolder.
export const zip = (source, target) => {
return Array.isArray(source)
? RNZipArchive.zipFiles(source.map(normalizeFilePath), normalizeFilePath(target))
: RNZipArchive.zipFolder(normalizeFilePath(source), normalizeFilePath(target));
};
On iOS, if you want to zip a file, then always enclose the filePath argument in array brackets, else you may get an empty 22-byte zip file on iOS.
await zip([filePath], zipPath)
I was digging through here after I had a problem a few months ago about zipping files; I ended up using the solution below to fix my problem as the zip times were hanging to about the 23-min mark similar to here:
""" On iOS, if you want to zip a file, then always enclose the filePath argument in array brackets, else you may get an empty 22-byte zip file on iOS.
await zip([filePath], zipPath)
"""
But, I ended up with an empty file as well.
TEST CASE (can be done on Simulator):
This results in a zip file size 100 bytes; pretty much empty.
If I remove the array, then the solution works again (for now?).
await zip(filePath, zipPath)
.
If anyone is inclined, try it out and let me know if there is a solution.
Currently, my solution is to place the media files in a different folder than my zip and see if that works out (only time will tell).
I ran into this again. I found code where I forgot to wrap filePath in brackets.
Explanation:
For the curious, the cause is the react-native-zip-archive index.js exports a single zip method, that uses the argument type to determine whether to call RNZipArchive.zipFiles or RNZipArchive.zipFolder.
export const zip = (source, target) => { return Array.isArray(source) ? RNZipArchive.zipFiles(source.map(normalizeFilePath), normalizeFilePath(target)) : RNZipArchive.zipFolder(normalizeFilePath(source), normalizeFilePath(target)); };
On iOS, if you want to zip a file, then always enclose the filePath argument in array brackets, else you may get an empty 22-byte zip file on iOS.
await zip([filePath], zipPath)
Actually, this is definitely a bug I want to fix.
Zip file is empty is iOS with react-native-zip-archive [6.0.3 & 6.0.2] same working fine in android. A clear and concise description of what the bug is.
To Reproduce Steps to reproduce the behavior: Try to zip a file without password using below code const targetPath =
${dirs.DocumentDir}/logs/${fileName}.zip
; Log.d(TAG_UTILITY, "ABC file path : " + filePath) Log.d(TAG_UTILITY, "ABC zip path : " + targetPath) zip(filePath, targetPath) .then(path => resolve({ filePath: path })) .catch(err => resolve({ filePath, error: err }))Expected behavior Zip should have the original file.
Env (please complete the following information):
Additional context The same code is working fine with 5.0.0 version which supports zipping files as well in iOS.