Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Tar Module - Extract tar files with Corona
Started by Danny Mar 12 2012 11:19 PM

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

neil24

[GLOBAL: userInfoPane.html]
neil24
  • Observer

  • 6 posts
  • Corona SDK

Is there an option to add a file to a TAR (or zip) for emailing?

I'd like to compress and add a password and then send a voice recorded file.

Thanks in advance.

Neil Friend
uid: 140436 topic_id: 23242 reply_id: 100333


[TOPIC: post.html]
#27

ezraanderson1979

[GLOBAL: userInfoPane.html]
ezraanderson1979
  • Contributor

  • 103 posts
  • Corona SDK

@neil24

with this version of tar there is no compression done, it basically just allows you to bundle files together.
uid: 89663 topic_id: 23242 reply_id: 100349


[TOPIC: post.html]
#28

neil24

[GLOBAL: userInfoPane.html]
neil24
  • Observer

  • 6 posts
  • Corona SDK

Thanks for the response, is there an option in Corona to add a password to a file before emailing it?

Thanks

Neil
uid: 140436 topic_id: 23242 reply_id: 100352


[TOPIC: post.html]
#29

ezraanderson1979

[GLOBAL: userInfoPane.html]
ezraanderson1979
  • Contributor

  • 103 posts
  • Corona SDK

@neil

Not that i am aware of at this time.
uid: 89663 topic_id: 23242 reply_id: 100619


[TOPIC: post.html]
#30

akao

[GLOBAL: userInfoPane.html]
akao
  • Contributor

  • 353 posts
  • Corona SDK

Danny - We would like to have our data file untar in the background without blocking the user interface. In general, I understand that co-routine is the approach to use for something like this in Lua. But how would you recommend that we implement it with this untar function? Is it even possible?

Really appreciate your help, this code really solves a lot of problems for us!
uid: 41124 topic_id: 23242 reply_id: 103223


[TOPIC: post.html]
#31

team1

[GLOBAL: userInfoPane.html]
team1
  • Contributor

  • 111 posts
  • Corona SDK

Doe this still exist? the link to the tar_lib.zip seems to be broken for me.
uid: 88147 topic_id: 23242 reply_id: 108081


[TOPIC: post.html]
#32

Danny

[GLOBAL: userInfoPane.html]
Danny
  • Corona Geek

  • 2,597 posts
  • Corona Staff

Sorry about that, I recently changed servers and didn't have a 100% up to date backup of my site.

Here is the new download link:

http://www.infuseddreams.com/apps/Tar_Lib.zip
@akao, does it block at the moment? I never tested for that, I will do some tests and see
uid: 84637 topic_id: 23242 reply_id: 108226


[TOPIC: post.html]
#33

kungpowell

[GLOBAL: userInfoPane.html]
kungpowell
  • Observer

  • 8 posts
  • Corona SDK

I have a completely noobie question, but I'm learning in crisis mode so my understanding is not very systematic. I have made a tar of images and posted them to my server. What I can't figure out is where in the main.lua to specify the pathname to the file. I have:

local fileToUntar = "images.tar"

But how do I set the path to "http://www.myserver.com/project/images.tar"?

Also, do I need to change anything in this line?:
tar.untar(fileToUntar, system.ResourceDirectory, system.DocumentsDirectory, onExtractComplete)

Thanks for helping un-noobing me.
uid: 97058 topic_id: 23242 reply_id: 113640


[TOPIC: post.html]
#34

ezraanderson1979

[GLOBAL: userInfoPane.html]
ezraanderson1979
  • Contributor

  • 103 posts
  • Corona SDK

download the file first to the system.TemporaryDirectory then extract it to the system.DocumentsDirectory. Thats how i do it there could be a better way.

tar.untar(fileToUntar, system.TemporaryDirectory, system.DocumentsDirectory, onExtractComplete)

http://developer.anscamobile.com/reference/index/networkdownload
uid: 89663 topic_id: 23242 reply_id: 113664


[TOPIC: post.html]
#35

kungpowell

[GLOBAL: userInfoPane.html]
kungpowell
  • Observer

  • 8 posts
  • Corona SDK

Thanks, ezraanderson1979. I now have the code working so the tar downloads but it does not seem to expand and the images it contains never load. Here's what I have for the relevant code in the main.lua. Anyone see an error?

local tar = require("tar")

local function networkListener( event )
if ( event.isError ) then
print ( "Network error - download failed" )
end
print ( "images" .. event.response )
end

network.download( "http://www.myserver.com/folder/folder/images.tar", "GET", networkListener, "images.tar", system.TemporaryDirectory )

local fileToUntar = "images.tar"

--Extract the file
tar.untar(fileToUntar, system.TemporaryDirectory, system.DocumentsDirectory, onExtractComplete)

imgDir = "images/"

Using the above code, I can see that the tar downloads into the cache but that's it. So I tried changing the system.TemporaryDirectory to system.ResourcesDirectory. This downloaded to the data folder but it never expanded either (yes, I also tried changing the tar.lua to reflect the change in the download directory). Any help is appreciated. Thanks!
uid: 97058 topic_id: 23242 reply_id: 113848


[TOPIC: post.html]
#36

akao

[GLOBAL: userInfoPane.html]
akao
  • Contributor

  • 353 posts
  • Corona SDK

Have you tried putting the tar into the Documents directory?
uid: 41124 topic_id: 23242 reply_id: 113856


[TOPIC: post.html]
#37

ezraanderson1979

[GLOBAL: userInfoPane.html]
ezraanderson1979
  • Contributor

  • 103 posts
  • Corona SDK

Try this

local tar = require("updatePackageTar")

local path = system.pathForFile( fileToUntar, system.TemporaryDirectory)
local fhd = io.open( path )

if fhd then
tar.untar(fileToUntar, system.TemporaryDirectory, system.DocumentsDirectory, onExtractComplete)
fhd:close()
else
end

edit: your code looks good to me. try putting print statements inside the tar.lua to see if the code is being executed ie: untar(filename, fileDir, destdir, onComplete) print('i am in the tar func')
uid: 89663 topic_id: 23242 reply_id: 113858


[TOPIC: post.html]
#38

kungpowell

[GLOBAL: userInfoPane.html]
kungpowell
  • Observer

  • 8 posts
  • Corona SDK

Thanks, ezraanderson1979, but I'm not quite sure I understand the first line since the tar is "tar.lua" not "updatePackageTar."

I put the rest of the code as-is directly after the code I posted previously, replacing nothing. The tar did not expand. I placed the code in the tar.lua, and nothing happened there either. Sorry to be a bit dense, but where would this code go, does it replace anything, and what does the first line mean.

Thanks very much!
uid: 97058 topic_id: 23242 reply_id: 113897


[TOPIC: post.html]
#39

kungpowell

[GLOBAL: userInfoPane.html]
kungpowell
  • Observer

  • 8 posts
  • Corona SDK

Yes,akao, but nothing happened.
uid: 97058 topic_id: 23242 reply_id: 113898


[TOPIC: post.html]
#40

akao

[GLOBAL: userInfoPane.html]
akao
  • Contributor

  • 353 posts
  • Corona SDK

@kungpowell You need to untar in your network download callback since the network callback is asynchronous.
uid: 41124 topic_id: 23242 reply_id: 113909


[TOPIC: post.html]
#41

kungpowell

[GLOBAL: userInfoPane.html]
kungpowell
  • Observer

  • 8 posts
  • Corona SDK

@akao - untar in the callback seemed to work. But the images still do not show up. So (hopefully) one last question. What is the pathname for my images? As as test, my first page of my app has images that look in two places and neither work. The tar is called "images.tar". I have one image looking for "images/myimage.png" and another looking for "my image.png". Now that I have the tar unpacked, is there an implication for the path I'm not accounting for? Again, thanks!
uid: 97058 topic_id: 23242 reply_id: 113924


[TOPIC: post.html]
#42

kungpowell

[GLOBAL: userInfoPane.html]
kungpowell
  • Observer

  • 8 posts
  • Corona SDK

@akao, here's how I ended up unpacking the tar:

local fileToUntar = "images.tar"
--IMAGES DOWNLOAD
local function networkListener( event )
tar.untar(fileToUntar, system.TemporaryDirectory, system.DocumentsDirectory, onExtractComplete)
end

network.download( "http://www.myserver.com/folder/folder/images.tar", "GET", networkListener, "images.tar", system.TemporaryDirectory )
uid: 97058 topic_id: 23242 reply_id: 113925


[TOPIC: post.html]
#43

Danny

[GLOBAL: userInfoPane.html]
Danny
  • Corona Geek

  • 2,597 posts
  • Corona Staff

@kungpowell, I don't see why you should prefix your image filenames with images/whatever.png.

Are they contained in a images subdirectory? if not the path would be just "whatever.png"

for instance:


display.newImage("whatever.png", system.DocumentsDirectory)

uid: 84637 topic_id: 23242 reply_id: 113983


[TOPIC: post.html]
#44

kungpowell

[GLOBAL: userInfoPane.html]
kungpowell
  • Observer

  • 8 posts
  • Corona SDK

@Danny, that was what I thought, but nothing ever displays. I think it may have to do with the different way the images are being called. I initially output the project via the Kwik plug-in and then heavily modified it, and their code is a bit different. The directory for the images is defined in the main.lua as

imgDir = ""
I've also tried
imgDir = system.DocumentsDirectory

In the individual pages they are called as

right = ui.newButton{
defaultSrc="p1_right@2.png",
overSrc="p1_right@2.png",
}

Everything seems to work as you all have suggested, but I think I have a slightly different starting point than we're solving for.You guys have been extremely helpful and very patient with me, and I don't want to wear out my welcome, so please forgive me if I'm asking for more help than these forums intended for. But if we can solve it here it may be helpful for other graphics-heavy apps made with Kwik.
uid: 97058 topic_id: 23242 reply_id: 114048


[TOPIC: post.html]
#45

mimetic

[GLOBAL: userInfoPane.html]
mimetic
  • Contributor

  • 160 posts
  • Corona SDK

I've restored the ability to handle directories. It will unpack directories and sub-directories. How do I get this to you?
uid: 37366 topic_id: 23242 reply_id: 129361


[TOPIC: post.html]
#46

mimetic

[GLOBAL: userInfoPane.html]
mimetic
  • Contributor

  • 160 posts
  • Corona SDK

Update: I figured out why this wasn't handling POSIX tar files from OS X. The octal_to_number function couldn't handle space-padded numbers. So, I added a trim() and it handles the tar files from OS X terminal without any trouble.

You should be able to get the files here:

https://github.com/mimetic/tar.lua.git
uid: 37366 topic_id: 23242 reply_id: 129385


[TOPIC: post.html]
#47

Danny

[GLOBAL: userInfoPane.html]
Danny
  • Corona Geek

  • 2,597 posts
  • Corona Staff

Nice work, thanks for sharing the changes!
uid: 84637 topic_id: 23242 reply_id: 129499


[TOPIC: post.html]
#48

PValentini

[GLOBAL: userInfoPane.html]
PValentini
  • Enthusiast

  • 60 posts
  • Corona SDK

Thank you all for the code...

I will use it to download content for my app, do you know how can I protect this content with password?

It is possible to partition this file for example a 50 mb in 10 parts of 5mb? With it I will simulate a progress of the download ;)

Thank you
uid: 6732 topic_id: 23242 reply_id: 130178


[TOPIC: post.html]
#49

PValentini

[GLOBAL: userInfoPane.html]
PValentini
  • Enthusiast

  • 60 posts
  • Corona SDK

Thank you all for the code...

I will use it to download content for my app, do you know how can I protect this content with password?

It is possible to partition this file for example a 50 mb in 10 parts of 5mb? With it I will simulate a progress of the download ;)

Thank you
uid: 6732 topic_id: 23242 reply_id: 130179


[TOPIC: post.html]
#50

Omnigeek Media

[GLOBAL: userInfoPane.html]
Omnigeek Media
  • Corona Geek

  • 2,975 posts
  • Corona SDK

Hey gang. I started to use this last night and I'm running into a problem.

Here is the error:
2012-11-10 11:12:30.277 Corona Simulator[458:707] princess.tar
2012-11-10 11:12:30.316 Corona Simulator[458:707] Runtime error
	...le/Projects/Technolio/TP_Series/TP-Shapes-V2/tar.lua:199: bad argument #1 to 'sub' (string expected, got userdata)
stack traceback:
	[C]: ?
	[C]: in function 'sub'
	...le/Projects/Technolio/TP_Series/TP-Shapes-V2/tar.lua:199: in function 'untar'
	...ects/Technolio/TP_Series/TP-Shapes-V2/gameselect.lua:29: in function 'unpackApp'

Here is the relevant code:

    print(storyboard.gameInfo[idx].filename)
    tar.untar(storyboard.gameInfo[idx].filename, system.CachesDirectory, system.CachesDirectory, onComplete)

princess.tar exists in my Caches folder (doing this in the simulator)

MacbookPros-MacBook-Pro:Caches rmiracle$ ls -l
total 49976
drwxr-xr-x  4 rmiracle  staff       136 Nov  9 23:18 princess
-rw-r--r--  1 rmiracle  staff  25584128 Nov  9 23:19 princess.tar

The unpacked folder I did by hand since I wanted to test further stuff until I figured out this error. The tar file is made up of sub-folders and I'm using the version from @ mimetic's https://github.com/mimetic/tar.lua.git

Any thoughts?
Thanks
Rob
uid: 19626 topic_id: 23242 reply_id: 130552



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