fsspec / fsspec/filesystem_spec
Unable to truncate file when using local storage
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.4k
- Forks
- 490
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 38
Description
Description
When trying to truncate a file while using local storage, an error is raised even if the provided mode is correct. This may be due to the missing implementation of truncate in LocalFileOpener.
To Reproduce
The following code raises io.UnsupportedOperation: truncate:
import fsspec
with fsspec.open("my_file.txt", mode="wb+") as stream:
stream.write(b"hello")
stream.truncate(2)
While this one works:
import fsspec
with fsspec.open("my_file.txt", mode="wb+") as stream:
stream.write(b"hello")
stream.f.truncate(2)
Environment
Python : 3.11.2
fsspec : 2023.6.0
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided Python reproduction, then inspect LocalFileOpener in fsspec/implementations/local.py around the referenced line. Confirm how stream.truncate differs from stream.f.truncate and check the surrounding local-file behavior. Done means the public stream.truncate(2) call works for the shown wb+ example without raising io.UnsupportedOperation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100