Parse a gzipped csv/tsv file

Viewed 99

I'm starting to use the parsecsv module (https://nim-lang.org/docs/parsecsv.html), and I was wondering if there's an easy way to seamlessly (same procedure for both plain text and compressed files) allow to parse gzipped files as well.

How would I do this? Thanks!

1 Answers

Just realized that parsecsv supports (of course) streams, so the library zip/gzipfiles can be used to open the stream.

import parsecsv
import zip/gzipfiles

let str = newGzFileStream(filename)
    parser.open(str, filename, separator = sep)
    while readRow(parser):
       ...
Related