You don't do bzip2 decompression in your program, just read uncompressed xml from stdin and parse it with libxml2 (or equvalent). Then just call your program like this, and enjoy the beuty of unix pipes:
bzip2 -d < planet.osm.bzip2 | yourtool
Question
What I want to do:
What I have:
Specific questions, to elaborate what my problem is:
I hope I have been able to clearly state my question, and I would be very thankful if someone could at least point me the right direction(s).
Thank you very much.
Update: Right after posting this I found out that libxml2 actually provides xmlTextReader from version 2.5.0 onwards, which partly addresses my question - but only partly, as I still don't know how to combine that with sequential bz2 file reading (and am open to totally different solutions still of course).
Update 2: The solution has to work from a permanently running process, and should be (as stated on point 2) memory+cpu efficient, so besides anything else there data should not be copied dozens of times (in memory or on disk).
Solution
You don't do bzip2 decompression in your program, just read uncompressed xml from stdin and parse it with libxml2 (or equvalent). Then just call your program like this, and enjoy the beuty of unix pipes:
bzip2 -d < planet.osm.bzip2 | yourtool