Couldn't uncompress file from system.TemporaryDirectory

Hello all, 

i’m trying to uncompress a simple zipfile from system.TemporaryDirectory. Even if file exists or not i got error.

The code below running fine when i changing zipBaseDir to system.ResourceDirectory.

Testing environment was the Corona simulator on windows.

local zip = require "plugin.zip"

local unzipOptions = { zipFile = "test.zip", zipBaseDir = system.TemporaryDirectory, dstBaseDir = system.TemporaryDirectory, listener = function(event) if ( event.isError ) then print("ERROR:",event.errorMessage) else print("OK") end end } local f = io.open(system.pathForFile("test.zip",system.TemporaryDirectory),"r") if f then print("File exists") io.close(f) end zip.list(unzipOptions) 

Output:

File exists ERROR: 

What i’m doing wrong?

so you are trying to unzip a file from temp directory to temp directory using the same source and destination filenames, and wonder why you get a file exist error?  :wink:

how is test.zip getting into the temporary directory? i.e. before you try to unzip it.

Thank you for the replies!

@anaquim:

the real problem is that i can use unzip if the basedir is NOT the resourcedir.

e.g: if the zipBaseDir equals with the system.DocumentsDirectory i get the same error

@roaminggamer:

manually copied. 

Have you tried setting the destination directory to a different one than the source directory? I havent used zip in a long time so dont remember much except that it works.
Usually syntax problems like these can be solved by studying the corona documentation.

i tried all combinations…

list or uncompress works without error only if zipBaseDir set to system.ResourceDir

local unzipOptions = { zipFile = "test.zip", zipBaseDir = system.ResourceDirectory, dstBaseDir = system.TemporaryDirectory, listener = function(event) if ( event.isError ) then print("ERROR:",event.errorMessage) else for k,v in pairs(event.response) do print(k,v.file) end end end } local f = io.open(system.pathForFile("test.zip",system.ResourceDirectory),"r") if f then print("File exists") io.close(f) end zip.list(unzipOptions) 

in this case the output is correct:

> File exists

> 1 data.json

Update: 

the problem not occours on mac!

copied manually the test.zip file to projects sandbox tmp folder, the output is correct when zipBaseDir=system.TemporaryDirectory

anybody can check the windows version? 

what OS did you originally have the issue on?

“Testing environment was the Corona simulator on windows.”

win10

checking the documentation I find that you are using options (dstBaseDir) not required to make a zip.list

if that has something to do with it or not, you need to test yourself.

every time i am stuck, going back to documentation with a magnifying glass often solves the problem.

https://docs.coronalabs.com/plugin/zip/list.html

I use zip in a windows app I have on the marketplace running on windows and mac without issues, so this has to be a syntax issue, unless something has changes regarding folder permissions, which I doubt.

you are rigth anaqim, the best example is to try to run example from the docs.

it’s working on mac, but not on windows. just tested.

Let us know what you find out :grinning:

Example from: https://docs.coronalabs.com/plugin/zip/list.html

can you test it on windows? i’m totally lost.

local zip = require( "plugin.zip" ) local function zipListener( event ) if ( event.isError ) then print( "Error!" ) else print ( event["type"] ) --\> list print( event.response ) --\> [1] = table: 0x618001466580 { --\> ratio: 98 --\> size: 2188295440 --\> file: space.jpg --\> [2] = table: 0x618001466580 { --\> ratio: 98 --\> size: 2188295440 --\> file: space1.jpg end end -- List all files from "test.zip" with additional file info local zipOptions = { zipFile = "test.zip", zipBaseDir = system.DocumentsDirectory, listener = zipListener } zip.list( zipOptions )

I can try tomorrow. Its 1am here so just typing on the phone while watching netflix :grinning:

thank you!  c u tomorrow.

Hi.  This is working fine for me in release 2018.3363.

Try this: https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/09/zip.zip

The example I linked above:

  1. zips some files from the resource directory into a file named test.zip and puts that zip file in the documents directory.
  2. one second later it decompresses that zip file into the temporary folder

PS - I tested this on Windows.  I’ll leave ‘testing on other OSes’ to all interested parties, but I’m 99.99% sure it will work.

Here is the code:

local zip = require( "plugin.zip" ) local function zipListener( event ) for k,v in pairs( event ) do print(k,v) end if ( event.isError ) then print( "Error!" ) else print ( "event.name: " .. event.name ) print ( "event.type: " .. event.type ) for k,v in pairs( event.response ) do print(k,v) end end end local function doCompress() local zipOptions = { zipFile = "test.zip", zipBaseDir = system.DocumentsDirectory, srcBaseDir = system.ResourceDirectory, srcFiles = { "sonic.png", "pinky.png" }, listener = zipListener } zip.compress( zipOptions ) end local function doUncompress() local zipOptions = { zipFile = "test.zip", zipBaseDir = system.DocumentsDirectory, dstBaseDir = system.TemporaryDirectory, listener = zipListener } zip.uncompress( zipOptions ) end doCompress() timer.performWithDelay( 1000, doUncompress )

Thank you for the code,

i think the problem is with my sandbox name on windows:

C:\Users\Bali János\AppData\Local\Corona Labs\Corona Simulator\Sandbox\ziptest-0FBE77187EC85ACAE06B437B48FD8691

As you see it has a non standard character. 

zip.list{ zipFile = "test.zip", zipBaseDir = system.ResourceDirectory, listener = function(event) print( "event.isError:",event.isError ) end }

While the name of my system.resourceDirectory “ZipTest” has only standard characters the zip plugin works.

Output is event.isError: false

Now i changed the project folder to “ZipTest János”.

The output is now: event.isError: true

Please help me how can i report this bug …

You can report a bug using the “Report a bug” link at the top of the forums page.

Please note, in production, you will not be manually copying a .zip file to your user’s tmp sandbox folder. You either have to include the .zip file in your project’s folder (with main.lua) and have code copy the file to a sandbox folder for you or download the file from the Internet somewhere. Your end users won’t have the skills to copy that file around.

While this tutorial talks about SQLite databases, it works for any binary file and can be used to populate your tmp folder with your .zip file from your app bundle:

https://coronalabs.com/blog/2015/05/19/tutorial-initializing-a-writable-sqlite-database-from-a-read-only-database/

Rob