I'm using the following approach to read a file line by line. This is a bogus
example that only returns each line, but you can imagine I am doing some work
on each line.
iterator line_iterator*(input_filename: string): string =
var infile: File
if open(infile, input_filename):
defer: close(infile)
var line: string
while not endOfFile(infile):
# Do some real work here
yield infile.readline.strip
Run
I would like to do exactly the same but reading lines within a gzip-compressed
file (eg: file.gz).
I'm trying to use import zip/gzipfiles and then use File, GzFile,
GzFileStream... but I'm failing.
What would my code above look like if I was iterating over the lines of a .gz
file?