Skip to content
Open
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
16 changes: 16 additions & 0 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,22 @@ such as ``.gz`` for gzip. Compression is not inferred by default:
``compression=None`` leaves the bytes unchanged, even if the filename ends in
``.gz``. The same ``compression`` argument is available on :func:`fsspec.open_files`.

Copying a file with :meth:`~fsspec.spec.AbstractFileSystem.get_file` is not
guaranteed to decompress it. The default implementation opens the source, but
some backends override the copy operation and may transfer the original bytes
rather than apply ``compression``. To decompress while copying regardless of
the backend's transfer implementation, open the source explicitly:

.. code-block:: python

from shutil import copyfileobj

import fsspec

with fsspec.open("example.txt.gz", "rb", compression="infer") as source:
with open("example.txt", "wb") as destination:
copyfileobj(source, destination)

Available codecs depend on your Python installation and optional packages.
Call :func:`fsspec.available_compressions` to see the codecs registered in the
current process. For example, ``"gzip"`` is a codec name, while ``None`` means no
Expand Down
8 changes: 7 additions & 1 deletion fsspec/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,13 @@ def cat(self, path, recursive=False, on_error="raise", **kwargs):
def get_file(
self, rpath, lpath=None, callback=DEFAULT_CALLBACK, outfile=None, **kwargs
):
"""Copy single remote file to local"""
"""Copy a single remote file to local.

The default implementation passes extra keyword arguments to
:meth:`open`. Backend implementations may use a different transfer
method and need not apply options such as compression. For a
decompressed stream, open the source with ``compression`` explicitly.
"""
from .implementations.local import LocalFileSystem

if outfile is None and isfilelike(lpath):
Expand Down