Question

I am currently implementing a custom std::filebuf which reads files from uncompressed .zip archives. For each file in the archive I have the offset into the archive file and the size. Now I want to limit the filebuf to the interval [offset, offset+size] so that I can use functions like pubseekoff() as if I have opened a normal file. For example when i do pubseekoff(5, std::ios::beg, std::ios::in); the filebuf should actually set it's underlying get-pointer to offset+5 in the archive file.

What would be the best way of implementing this? I tried to derive from std::filebuf and override functions like seekoff() to do the local file offset -> archive file offset conversions but that didn't work since the underlying filebuf (wich doesn't know anything about my archive-offsets) calls these functions and throws eof errors and the like. I also tried to derive from std::streambuf and use a std::filebuf inside my streambuf, but that also didn't work since most members in std::streambuf are protected. I could use a std::ifstream inside my streambuf but that seems to be cumbersome.

Was it helpful?

Solution

I ended up rewriting a streambuf from scratch. It uses the C-Style fopen(), fread() etc. functions. The code is not very well tested (neither for correctness nor for performance) but it works for me:

http://pastebin.com/Bt4rh0mu

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top