diff --git a/sshfs/spec.py b/sshfs/spec.py index 954c7bd..591d714 100644 --- a/sshfs/spec.py +++ b/sshfs/spec.py @@ -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() diff --git a/tests/test_sshfs.py b/tests/test_sshfs.py index 663f778..47d4c12 100644 --- a/tests/test_sshfs.py +++ b/tests/test_sshfs.py @@ -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."