Use buffered IO

free ~10% speedup on read, probably similar on write
This commit is contained in:
Jan Petykiewicz 2019-05-15 23:50:31 -07:00
parent a461446059
commit 376cbcce26

View File

@ -124,7 +124,7 @@ def writefile(patterns: List[Pattern] or Pattern,
else:
open_func = open
with open_func(path, mode='wb') as stream:
with io.BufferedWriter(open_func(path, mode='wb')) as stream:
results = write(patterns, stream, *args, **kwargs)
return results
@ -218,7 +218,7 @@ def readfile(filename: str or pathlib.Path,
else:
open_func = open
with open_func(path, mode='rb') as stream:
with io.BufferedReader(open_func(path, mode='rb')) as stream:
results = read(stream, *args, **kwargs)
return results