summaryrefslogtreecommitdiff
path: root/fs/iotools.py
diff options
context:
space:
mode:
Diffstat (limited to 'fs/iotools.py')
-rw-r--r--fs/iotools.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/fs/iotools.py b/fs/iotools.py
index f2e0f6e..bf91ec3 100644
--- a/fs/iotools.py
+++ b/fs/iotools.py
@@ -211,6 +211,30 @@ def copy_file_to_fs(f, fs, path, encoding=None, errors=None, progress_callback=N
return bytes_written
+def line_iterator(f, size=None):
+ """A not terribly efficient char by char line iterator"""
+ read = f.read
+ line = []
+ append = line.append
+ c = 1
+ if size is None or size < 0:
+ while c:
+ c = read(1)
+ if c:
+ append(c)
+ if c in (b'\n', b''):
+ yield b''.join(line)
+ del line[:]
+ else:
+ while c:
+ c = read(1)
+ if c:
+ append(c)
+ if c in (b'\n', b'') or len(line) >= size:
+ yield b''.join(line)
+ del line[:]
+
+
if __name__ == "__main__":
print("Reading a binary file")
bin_file = open('tests/data/UTF-8-demo.txt', 'rb')