Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Couldn't uncompress file from system.TemporaryDirectory
Started by bali.janos Sep 30 2018 06:26 AM

- - - - -
25 replies to this topic
zip plugin uncompress

[TOPIC CONTROLS]
Page 1 of 2 1 2
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

bali.janos

[GLOBAL: userInfoPane.html]
bali.janos
  • Observer

  • 19 posts
  • Corona SDK

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?



[TOPIC: post.html]
#2

anaqim

[GLOBAL: userInfoPane.html]
anaqim
  • Contributor

  • 770 posts
  • Corona SDK

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?  ;)



[TOPIC: post.html]
#3

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,587 posts
  • Corona SDK

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



[TOPIC: post.html]
#4

bali.janos

[GLOBAL: userInfoPane.html]
bali.janos
  • Observer

  • 19 posts
  • Corona SDK

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. 



[TOPIC: post.html]
#5

anaqim

[GLOBAL: userInfoPane.html]
anaqim
  • Contributor

  • 770 posts
  • Corona SDK

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.

[TOPIC: post.html]
#6

bali.janos

[GLOBAL: userInfoPane.html]
bali.janos
  • Observer

  • 19 posts
  • Corona SDK

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


[TOPIC: post.html]
#7

bali.janos

[GLOBAL: userInfoPane.html]
bali.janos
  • Observer

  • 19 posts
  • Corona SDK

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? 



[TOPIC: post.html]
#8

anaqim

[GLOBAL: userInfoPane.html]
anaqim
  • Contributor

  • 770 posts
  • Corona SDK

what OS did you originally have the issue on?



[TOPIC: post.html]
#9

bali.janos

[GLOBAL: userInfoPane.html]
bali.janos
  • Observer

  • 19 posts
  • Corona SDK

"Testing environment was the Corona simulator on windows."

 

win10



[TOPIC: post.html]
#10

anaqim

[GLOBAL: userInfoPane.html]
anaqim
  • Contributor

  • 770 posts
  • Corona SDK

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


[TOPIC: post.html]
#11

anaqim

[GLOBAL: userInfoPane.html]
anaqim
  • Contributor

  • 770 posts
  • Corona SDK

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.



[TOPIC: post.html]
#12

bali.janos

[GLOBAL: userInfoPane.html]
bali.janos
  • Observer

  • 19 posts
  • Corona SDK

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.



[TOPIC: post.html]
#13

anaqim

[GLOBAL: userInfoPane.html]
anaqim
  • Contributor

  • 770 posts
  • Corona SDK

Let us know what you find out 😀

[TOPIC: post.html]
#14

bali.janos

[GLOBAL: userInfoPane.html]
bali.janos
  • Observer

  • 19 posts
  • Corona SDK

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 )


[TOPIC: post.html]
#15

anaqim

[GLOBAL: userInfoPane.html]
anaqim
  • Contributor

  • 770 posts
  • Corona SDK

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

[TOPIC: post.html]
#16

bali.janos

[GLOBAL: userInfoPane.html]
bali.janos
  • Observer

  • 19 posts
  • Corona SDK

thank you!  c u tomorrow.



[TOPIC: post.html]
#17

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,587 posts
  • Corona SDK

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.


Edited by roaminggamer, 30 September 2018 - 03:29 PM.


[TOPIC: post.html]
#18

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,587 posts
  • Corona SDK

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 )


[TOPIC: post.html]
#19

bali.janos

[GLOBAL: userInfoPane.html]
bali.janos
  • Observer

  • 19 posts
  • Corona SDK

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 ...



[TOPIC: post.html]
#20

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,925 posts
  • Enterprise

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



[TOPIC: post.html]
#21

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,587 posts
  • Corona SDK

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


@bali - So you downloaded and ran my example and it did not work?

[TOPIC: post.html]
#22

bali.janos

[GLOBAL: userInfoPane.html]
bali.janos
  • Observer

  • 19 posts
  • Corona SDK

Hi. 

 

@roaringgamer: 

Thank you for your advices you helped me a lot! I tried your code, but the result was same... 

Finally i'm found that the maybe the zip plugin can't handle international characters in the filepath. 

 

@Rob:

Thank you too. I'll never try to copy files manually in production environment. I made this small sample to detect why the downloaded file is unaccessible for me from the simulator on windows. 

The tutorial is another good example to notice that something wrong in the zip plugin, because using the system.pathForFile(...) always worked for me in my programs to access files at temp or docs dir.

Do you think it's enough information for a bug report or i need do more tests?

 

janos



[TOPIC: post.html]
#23

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,925 posts
  • Enterprise

It sounds like there is a problem with UTF-8 characters in path names. That should be sufficient to provide a bug report.

 

Rob



[TOPIC: post.html]
#24

bali.janos

[GLOBAL: userInfoPane.html]
bali.janos
  • Observer

  • 19 posts
  • Corona SDK

Update:

I made the final test.

 

I created a new windows user with no hungarian characters in the username.

Everything is working perfectly now, tested with roaringgamers code.

 

thank you for helping me



[TOPIC: post.html]
#25

bali.janos

[GLOBAL: userInfoPane.html]
bali.janos
  • Observer

  • 19 posts
  • Corona SDK

Rob the bug report was provided just now. thx again.

Maybe you should close this topic?




[topic_controls]
Page 1 of 2 1 2
 
[/topic_controls]