For ensuring file closing:
    
    
    var fh = open(filename)
    defer close(fh) # close fh at the end of current block
    process(fh)
    

Encoding is not part of the file opening process in Nim. A file is just read 
byte for byte. If, for example, you want to open a latin-1 file and get a UTF-8 
string, you could do this:
    
    
    import encodings
    var content = convert(readAll(filename), srcEncoding="ISO-8859-1")
    

Note that I am using `readAll` which opens and closes the file automatically. 
You can also use the method shown above, instantiate an `EncodingConverter` and 
then read and convert each line / character / whatever individually.

Reply via email to