Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fsspec buffered reading #156

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading