Skip to content

Commit 79f7661

Browse files
authored
Add _cat_file (#45)
1 parent c127831 commit 79f7661

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

sshfs/spec.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,10 @@ async def _execute(self, *args, **kwargs):
316316

317317
def _open(self, path, *args, **kwargs):
318318
return SSHFile(self, path, *args, **kwargs)
319+
320+
@wrap_exceptions
321+
async def _cat_file(self, path, **kwargs):
322+
"""Asynchronously fetch the contents of a file"""
323+
async with self._pool.get() as channel:
324+
async with channel.open(path, "rb") as f:
325+
return await f.read()

tests/test_sshfs.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,21 @@ def test_concurrency_for_raw_commands(fs, remote_dir):
337337
]
338338
for future in futures.as_completed(cp_futures):
339339
future.result()
340+
341+
342+
def test_cat_file_sync(fs, remote_dir):
343+
# Define the content to write to the test file
344+
test_content = b"Test content for cat_file"
345+
test_file_path = remote_dir + "/test_file.txt"
346+
347+
# Write content to the file synchronously
348+
with open(test_file_path, "wb") as f:
349+
f.write(test_content)
350+
351+
# Use the cat_file method to read the content back synchronously
352+
read_content = fs.cat_file(test_file_path)
353+
354+
# Verify the content read is the same as the content written
355+
assert (
356+
read_content == test_content
357+
), "The content read from the file does not match the content written."

0 commit comments

Comments
 (0)