Skip to content

feat: Read MP3, FLAC, and WAV without the audio payload - #105

Merged
decriptor merged 3 commits into
mainfrom
fix/read-stream
Nov 17, 2026
Merged

decriptor merged 3 commits into
mainfrom
fix/read-stream

Conversation

@decriptor

@decriptor decriptor commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • MediaFile.Read and ReadAsync accept a Stream, so an upload does not have to be written to a temp file first. The caller keeps ownership of the stream.
  • A seekable MP3, FLAC, or WAV is read from the tag and header ranges. The audio payload stays unread. A stream that cannot seek is copied once and then parsed as before.
  • Saving a WAV that was opened from a path reloads the samples from that path. Saving a WAV that was opened from a stream with no path fails instead of writing silence.
  • A Matroska file opened from a path still records that path, so SaveToFile() can write it back. A stream opened with only a path hint does not.

Fixes #54
Part of #20

Test plan

  • An MP3, FLAC, and WAV with a 1 MB audio gap are read from a stream, and the bytes read stay far below the file size
  • The same MP3 read from a path does not call ReadAllBytes
  • A non-seekable stream still returns the title
  • MediaFile.Read and ReadAsync on a Matroska path set SourcePath and a save round-trips
  • Full net8.0 suite: 4291 passed, 10 skipped
  • Library builds for netstandard2.0, netstandard2.1, net8.0, and net10.0

Still open on #20

AIFF, MP4, Ogg, WavPack, Musepack, Monkey's Audio, DSF, DFF, ASF, and Matroska still read the whole file into one array. AIFF is the chunked sibling of WAV.

@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.90365% with 140 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.97%. Comparing base (113c244) to head (d76f0f4).

Files with missing lines Patch % Lines
...ts/TagLibSharp2.Tests/Core/MediaFileStreamTests.cs 76.62% 30 Missing and 6 partials ⚠️
...s/TagLibSharp2.Tests/Core/WindowedReadEdgeTests.cs 88.85% 28 Missing and 4 partials ⚠️
...TagLibSharp2.Tests/Core/WindowedReadDefectTests.cs 87.38% 26 Missing and 2 partials ⚠️
src/TagLibSharp2/Xiph/FlacFile.cs 77.77% 6 Missing and 6 partials ⚠️
src/TagLibSharp2/Core/MediaFile.cs 85.52% 5 Missing and 6 partials ⚠️
src/TagLibSharp2/Mpeg/Mp3File.cs 88.42% 6 Missing and 5 partials ⚠️
src/TagLibSharp2/Riff/RiffFile.cs 90.00% 2 Missing and 2 partials ⚠️
src/TagLibSharp2/Mpeg/MpegAudioProperties.cs 70.00% 1 Missing and 2 partials ⚠️
src/TagLibSharp2/Riff/WavFile.cs 94.44% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #105      +/-   ##
==========================================
- Coverage   93.07%   92.97%   -0.11%     
==========================================
  Files         278      282       +4     
  Lines       53151    54202    +1051     
  Branches     4831     4961     +130     
==========================================
+ Hits        49470    50392     +922     
- Misses       2168     2260      +92     
- Partials     1513     1550      +37     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

MediaFile.Read and ReadAsync accept a stream. A seekable MP3, FLAC, or
WAV is read from its tags and headers, so a scan does not allocate the
audio. A stream that cannot seek is copied once.
MediaFile.Read and ReadAsync still record the path so a later save can find the file. A stream opened with only a path hint does not.
@decriptor
decriptor merged commit 851b03f into main Nov 17, 2026
8 checks passed
@decriptor
decriptor deleted the fix/read-stream branch November 17, 2026 07:50
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.

[Feature]: Add Stream support to MediaFile.ReadAsync

1 participant