Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: encoder handling WriteSeeker #383

Merged
merged 2 commits into from
Aug 31, 2024
Merged

Conversation

muktihari
Copy link
Owner

@muktihari muktihari commented Aug 31, 2024

  • Unnexpected "encoder internal error" occurs when passing io.WriteSeeker as io.Writer since we forgot to early return. Previously, we treat an io.Writer that implements both io.WriterAt and io.WriteSeeker, such as *os.File, as io.WriterAt so users using *os.File does not affected by this bug. The bug only affects io.Writer that only implement io.WriteSeeker.
  • Now io.Writer that implements both io.WriterAt and io.WriteSeeker will be treated as io.WriteSeeker. We change this to prevent wrong write on a io.Writer that is not empty (existing file) as we will aways write at offset 0 to update the header while offset 0 might not be our own content. By treating it as io.WriteSeeker, we can seek relative to EOF so we ensure that we write on our own data. This also enable us to append to existing file to create a chained FIT file.
  • Add caveats documentation when users are using io.Writer that solely implements io.WriterAt must provide an empty writer.
  • In most cases, we encode to a brand new file, so the bug is unlikely to occur broadly.

@muktihari muktihari added the bug Something isn't working label Aug 31, 2024
@muktihari muktihari self-assigned this Aug 31, 2024
@codecov-commenter
Copy link

codecov-commenter commented Aug 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (0af34cf) to head (90d9661).

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #383   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           41        41           
  Lines         3682      3682           
=========================================
  Hits          3682      3682           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@muktihari muktihari merged commit 093863a into master Aug 31, 2024
4 checks passed
@muktihari muktihari deleted the fix/encoder-write-seeker branch August 31, 2024 08:10
@muktihari muktihari added this to the v0.21.3 milestone Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants