Advertisement
treyhunner

read_chunks on Path 1

Apr 5th, 2019
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.27 KB | None | 0 0
  1. from pathlib import Path
  2.  
  3. def read_chunks(self, size=1024, *, mode='rb'):
  4.     with self.open(mode) as f:
  5.         sentinel = b'' if 'b' in mode else ''
  6.         for chunk in iter(lambda: f.read(size), sentinel):
  7.             yield chunk
  8.  
  9. Path.read_chunks = read_chunks
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement