I'd like to be able to read from a text file that can be gzipped and can come as a stream from stdin.
import zip/gzipfiles # Import zip package
# get "inputFile" being a string with the filename or "-" to read from STDIN?
if inputFile == "-":
inputFile = "/dev/stdin"
let file = newGzFileStream(inputFile)
defer: file.close()
var line: string # Declare line variable
while not file.atEnd():
line = file.readLine()
echo line
The way I implemented it cat file.txt(.gz) | my_prog results in checking the first argument, if not supplied, or if equal to "-", the program sets inputFile to "/dev/stdin".
I don't know if this is a correct way, and can be ported from one POSIX system to another, for example, or if there's a "proper" way (I'd like to have better words to formulate the question).