Skip to content

fix: Files[io].writeAll does not create file unnecessarily. #3367 #3688

Open
ankitkumarrain wants to merge 2 commits intotypelevel:mainfrom
ankitkumarrain:issue-3367
Open

fix: Files[io].writeAll does not create file unnecessarily. #3367 #3688
ankitkumarrain wants to merge 2 commits intotypelevel:mainfrom
ankitkumarrain:issue-3367

Conversation

@ankitkumarrain
Copy link

@ankitkumarrain ankitkumarrain commented Mar 5, 2026

Summary

Fixes #3667

Bug

writeAll used Stream.resource(writeCursor(...)) which eagerly opens
and creates the file during resource acquisition — before any bytes
are pulled from the input stream.

Fix

Use pull.stepLeg to peek at the input stream first:
Stepleg takes first chunk scpoe safely.

  • Empty stream → file is never created
  • Erroring stream → error propagates, file never created
  • Normal stream → behavior unchanged

Files Changed

  • io/shared/src/main/scala/fs2/io/file/Files.scala
  • io/js/src/main/scala/fs2/io/file/FilesPlatform.scala

@ankitkumarrain
Copy link
Author

@mpilquist , Can you please review this code .

@armanbilge
Copy link
Member

@ankitkumarrain thanks for the PR. Before we review it would you mind making a contribution to our onboarding repository? Directions are in the README.

https://github.com/typelevel/gsoc-onboarding

Please review our AI policy and update your PR accordingly.

https://typelevel.org/gsoc/ai.html

@ankitkumarrain ankitkumarrain changed the title fix: defer file creation in writeAll until first byte arrives #3367 fix: Files[io].writeAll does not create file unnecessarily. #3367 Mar 7, 2026
@ankitkumarrain
Copy link
Author

@armanbilge Thanks for comment on this pull request .I have read AI policy and updated pull request Accordingly. Can you please review this pull request as i understand the code i have written. I visited to onboarding repository that was very fantastic i would really like to add my component there . Thank you for your time.
Best Regards !
Ankit
@ankitkumarrain

@mpilquist
Copy link
Member

Hi Ankit -- please be sure to complete the onboarding task first.

Re: this PR, what's the behavior when writing an empty stream to a file? What's the desired behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Files[IO].writeAll creates file when it shouldn't

3 participants