lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



* On 2008-05-09 George Petsagourakis <petsagouris@gmail.com> wrote  :

> Basically I need to access a file named "somefile.xml.bz2" it has an xml inside.
> Any easy ideas how to read the xml to a string without even downloading the file?

If you're on a unix machine with the proper tools installed, something
like this might work for you:

cmd = "curl -s http://address/your/archive.tar.bz2 | bzip2 -d | tar -O -xf - file.xml"
f = io.popen(cmd)
xml = f:read("*a")
f:close()

- curl downloads the archive and send to stdout
- 'bzip2 -d' decompresses the stream
- tar tries to extract the 'file.xml' document and sends this to stdout

This all wrapped in a io.popen() call allowes you to read the final
output into a variable.  This of course downloads the file, but does not
need to save a local copy.

-- 
:wq
^X^Cy^K^X^C^C^C^C