xxxxxxxxxx
import std.stdio, std.algorithm, std.zlib;
import std.range.primitives;
void main(string[] args)
{
auto f = GZippedFile(File(args[1], "rb"));
f.splitter("\n").each!writeln;
}
struct GZippedFile
{
File file;
UnCompress uncompressor;
ubyte[] readBuffer;
const(char)[] buffer;
this(File f) {
file = f;
uncompressor = new UnCompress(HeaderFormat.gzip);
readBuffer = new ubyte[4096];
}
dchar front() const {
return buffer.front;
}
void popFront() {
if (buffer.empty) {
buffer = cast(const(char)[])
uncompressor.uncompress(file.rawRead(readBuffer));
}
else {
buffer.popFront();
}
}
bool empty() {
return buffer.empty && file.eof();
}
}