def createParser(filename, real_filename=None, tags=None):
"""
Create a parser from a file or returns None on error.
Options:
- file (str|io.IOBase): Input file name or
a byte io.IOBase stream ;
- real_filename (str): Real file name.
"""
if not tags:
tags = []
stream = FileInputStream(filename, real_filename, tags=tags)
guess = guessParser(stream)
if guess is None:
stream.close()
return guess
You should return stream with guess. You should let us close stream.
hachoir/parser/guess.py