Skip to content

Commit

Permalink
Add _cat_file (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
kephale authored Apr 21, 2024
1 parent c127831 commit 79f7661
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sshfs/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,10 @@ async def _execute(self, *args, **kwargs):

def _open(self, path, *args, **kwargs):
return SSHFile(self, path, *args, **kwargs)

@wrap_exceptions
async def _cat_file(self, path, **kwargs):
"""Asynchronously fetch the contents of a file"""
async with self._pool.get() as channel:
async with channel.open(path, "rb") as f:
return await f.read()
18 changes: 18 additions & 0 deletions tests/test_sshfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,21 @@ def test_concurrency_for_raw_commands(fs, remote_dir):
]
for future in futures.as_completed(cp_futures):
future.result()


def test_cat_file_sync(fs, remote_dir):
# Define the content to write to the test file
test_content = b"Test content for cat_file"
test_file_path = remote_dir + "/test_file.txt"

# Write content to the file synchronously
with open(test_file_path, "wb") as f:
f.write(test_content)

# Use the cat_file method to read the content back synchronously
read_content = fs.cat_file(test_file_path)

# Verify the content read is the same as the content written
assert (
read_content == test_content
), "The content read from the file does not match the content written."

0 comments on commit 79f7661

Please sign in to comment.