From ed3e91b5fa5af217a8e0e01aa7c8d641752d752d Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Thu, 7 Mar 2024 19:11:45 -0800 Subject: [PATCH] Add method read_generator. --- voussoirkit/pathclass.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/voussoirkit/pathclass.py b/voussoirkit/pathclass.py index 3b28549..937366b 100644 --- a/voussoirkit/pathclass.py +++ b/voussoirkit/pathclass.py @@ -437,6 +437,14 @@ class Path: with self.open(mode, **kwargs) as handle: return handle.read() + def read_generator(self, mode, chunk_size, **kwargs): + with self.open(mode, **kwargs) as handle: + while True: + chunk = handle.read(chunk_size) + if not chunk: + break + yield chunk + def readlines(self, mode, **kwargs): ''' Shortcut function for opening the file handle and reading lines from it.