On Wednesday, 19 February 2014 at 16:36:29 UTC, Adam D. Ruppe
wrote:
On Wednesday, 19 February 2014 at 16:27:32 UTC, Artem Tarasov
wrote:
Unfortunately, there's no standard module for processing
gzip/bz2.
std.zlib handles gzip but it doesn't present a file nor range
interface over it.
This will work though:
void main() {
import std.zlib;
import std.stdio;
auto uc = new UnCompress();
foreach(chunk; File("testd.gz").byChunk(1024)) {
auto uncompressed = uc.uncompress(chunk);
writeln(cast(string) uncompressed);
}
// also look at anything left in the buffer
writeln(cast(string) uc.flush());
}
Regrettably, the above code has a bug. Currently, std.zlib stores
a reference to the buffer passed to it, and since byChunk reuses
the buffer, the code will fail when uncompressing multiple chunks.