Page 1 of 1
revZipExtractItemToFile on iOS
Posted: Thu Aug 30, 2012 1:15 pm
by endernafi
Hello dear LiveCoders,
I'm trying to update my app(s) but the database is huge.
So, I thought that I can zip it, then download it, then extract it to the actual file on the device.
But it didn't work.
App freezes trying to unzip the file.
Here is my code:
Code: Select all
on doTheUpdate
if checkConnection() then
put "http://www.example.com/myDatabase.zip" into theSource
put specialFolderPath("documents") & "/database_temp.zip" into theTempFile
put specialFolderPath("documents") & "/actualDatabase.sqlite" into theTarget
libUrlDownloadToFile theSource, theTempFile
if ((there is a file theTempFile) and (calcTheFileSize(specialFolderPath("documents"), "database_temp.zip") > 0)) then
revZipExtractItemToFile theTempFile, "actualDatabase.sqlite", theTarget
answer the result
/* no result whatsoever, it just freezes, black screen */
delete file theTempFile
end if
end if
end doTheUpdate
What am I doing wrong, any ideas?
Regards,
~ Ender Nafi Elekcioglu
Re: revZipExtractItemToFile on iOS
Posted: Thu Aug 30, 2012 1:25 pm
by Klaus
Hi Ender,
please note his important sentence (from the dictionary

...
Use the revZipExtractItemToFile command to place an item in zip archive into a file on disk.
The archive must first have been opened using the revZipOpenArchive command.
...
I think this is the culprit.
Best
Klaus
Re: revZipExtractItemToFile on iOS
Posted: Thu Aug 30, 2012 1:39 pm
by endernafi
Hi Klaus,
Thanks for the quick reply,
I was hopeful but no luck; black screen again
Here is my code:
Code: Select all
on doTheUpdate
if checkConnection() then
put "http://www.example.com/myDatabase.zip" into theSource
put specialFolderPath("documents") & "/database_temp.zip" into theTempFile
put specialFolderPath("documents") & "/actualDatabase.sqlite" into theTarget
libUrlDownloadToFile theSource, theTempFile
if ((there is a file theTempFile) and (calcTheFileSize(specialFolderPath("documents"), "database_temp.zip") > 0)) then
revZipOpenArchive theTempFile, "read"
revZipExtractItemToFile theTempFile, "actualDatabase.sqlite", theTarget
revZipCloseArchive theTempFile
delete file theTempFile
end if
end if
end doTheUpdate
Btw, I watch the process within Finder.
It downloads the zip file and I can unzip that zip file via Finder.
There isn't any problem with the zip or the sqlite file.
Regards,
~ Ender Nafi Elekcioglu
Re: revZipExtractItemToFile on iOS
Posted: Thu Aug 30, 2012 1:47 pm
by endernafi
Ok, I found what's wrong.
I'll begin to suspect that I'm stupid
I didn't check that little box "Externals: revZip" on Standalone Application Settings.
Now, it's all fine.
Klaus, thanks again.
Regards,
~ Ender Nafi Elekcioglu
Re: revZipExtractItemToFile on iOS
Posted: Thu Aug 30, 2012 1:54 pm
by Klaus
Bi Ender,
hmmm, the script looks OK.
But "liburldownloadtofile" is asynchronously, so right after that command
only a small portion of the actual file is actually downloaded already, if at all!
I would us a "callback" message, check "liburldownloadtofile" in the dicitonary.
Something like this:
Code: Select all
on doTheUpdate
## Avoid unneccessary nested "if... then..." clauses ;-)
if checkConnection() = false then
exit mouseup
end if
put "http://www.example.com/myDatabase.zip" into theSource
put specialFolderPath("documents") & "/database_temp.zip" into theTempFile
## The callback message will be sent when the download is complete (or failed somehow)
libUrlDownloadToFile theSource, theTempFile, "do_the_un_zip"
# Done here!
end doTheUpdate
command do_the_un_zip
put specialFolderPath("documents") & "/database_temp.zip" into theTempFile
put specialFolderPath("documents") & "/actualDatabase.sqlite" into theTarget
if ((there is a NOT A file theTempFile) OR (calcTheFileSize(specialFolderPath("documents"), "database_temp.zip") <= 0)) then
answer "Error..."
exit do_the_un_zip
end if
revZipOpenArchive theTempFile, "read"
revZipExtractItemToFile theTempFile, "actualDatabase.sqlite", theTarget
revZipCloseArchive theTempFile
delete file theTempFile
end do_the_un_zip
If you want the download to be blocking, use:
...
put url("
http://server.com/online.zip") into url("binfile:" & specialFolderPath("documents") & "/database_temp.zip")
## Script will halt until file is downloaded or an error has occured!
## check for file and unzip if present now...
...
Best
Klaus
Re: revZipExtractItemToFile on iOS
Posted: Thu Aug 30, 2012 2:05 pm
by endernafi
Thank you Klaus,
I'll prefer the "callback message" way,
because that
put url ... into url ... syntax never did good for me

I encounter odd behaviours of my app(s) from time to time.
Well, thanks again...
Regards,
~ Ender Nafi
Re: revZipExtractItemToFile on iOS
Posted: Thu Aug 30, 2012 2:10 pm
by Klaus
Hi Ender,
sorry, I overlooked "on iOS"!
On iOS "liburldownloadtofile" IS indeed blocking!
Anyway, I would use a callback message nevertheless, but in that case you need to
use "LOAD" instead of "liburldownloadtofile".
Code: Select all
...
put "http://www.example.com/myDatabase.zip" into theSource
put specialFolderPath("documents") & "/database_temp.zip" into theTempFile
## The callback message will be sent when the download is complete (or failed somehow)
LOAD theSource, "do_the_un_zip"
...
## And then do soemthign like this (out of my head!)
command do_the_un_zip tUrl, tStatus, tData
if tStatus <> "downloaded" then
answer "Error" && tStatus
exit do_the_un_zip
end if
put specialFolderPath("documents") & "/database_temp.zip" into theTempFile
put specialFolderPath("documents") & "/actualDatabase.sqlite" into theTarget
## Now save the CACHED url to file:
put url tUrl into url("binfile:" & theTempFile)
revZipOpenArchive theTempFile, "read"
revZipExtractItemToFile theTempFile, "actualDatabase.sqlite", theTarget
revZipCloseArchive theTempFile
delete file theTempFile
end do_the_un_zip
Check the "iOS Release Notes" (Menu: Help) for more info, look for "Non-file URL access".
Best
Klaus
Re: revZipExtractItemToFile on iOS
Posted: Thu Aug 30, 2012 2:15 pm
by endernafi
Thanks Klaus,
By the way, I found what's actually wrong.
I didn't check that little box "Externals: revZip" on Standalone Application Settings
Now, it's all fine
Regards,
~ Ender Nafi
Re: revZipExtractItemToFile on iOS
Posted: Thu Aug 30, 2012 2:18 pm
by Klaus
Well, no comment...
