summaryrefslogtreecommitdiff
path: root/fs/iotools.py
diff options
context:
space:
mode:
authorwillmcgugan@gmail.com <willmcgugan@gmail.com@67cdc799-7952-0410-af00-57a81ceafa0f>2014-10-16 14:07:23 +0000
committerwillmcgugan@gmail.com <willmcgugan@gmail.com@67cdc799-7952-0410-af00-57a81ceafa0f>2014-10-16 14:07:23 +0000
commit369aa5f4627a47cc4fade7cc5c440be6a9387236 (patch)
tree6873e2b9ff07b8a54a6117d949c85b95d503d181 /fs/iotools.py
parentd62262101db3314f70355d040ca3808f05e22ede (diff)
downloadpyfilesystem-git-369aa5f4627a47cc4fade7cc5c440be6a9387236.tar.gz
Fixes, including hang bug in readline
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')