Skip to content

Commit

Permalink
Fsspec buffered reading (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimahriman authored Nov 6, 2024
1 parent ffd719a commit af34ed5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion python/hdfs_native/fsspec.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import io
import secrets
import shutil
import time
Expand Down Expand Up @@ -165,7 +166,10 @@ def _open(
):
path = self._strip_protocol(path)
if mode == "rb":
return self.client.read(path)
reader = self.client.read(path)
if not block_size:
return reader
return io.BufferedReader(reader, buffer_size=block_size)
elif mode == "wb":
write_options = WriteOptions()
write_options.overwrite = overwrite
Expand Down
4 changes: 4 additions & 0 deletions python/tests/test_fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def test_io(fs: HdfsFileSystem):
data = file.read()
assert data == b"hello there"

with fs.open("/test", mode="rb", block_size=1024) as file:
data = file.read()
assert data == b"hello there"

fs.write_bytes("/test2", b"hello again")
assert fs.read_bytes("/test2") == b"hello again"
assert fs.read_bytes("/test2", start=1) == b"ello again"
Expand Down

0 comments on commit af34ed5

Please sign in to comment.