fsspec / fsspec/filesystem_spec

Unable to truncate file when using local storage

Open
#1,338 5 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.