Support non-seekable streams in FromStream method#66
Conversation
There was a problem hiding this comment.
Pull request overview
Updates PdqHasher.FromStream to handle non-seekable input streams by buffering them into a seekable MemoryStream before handing off to SkiaSharp, and adjusts the related unit test to properly signal EOF on the pipe writer.
Changes:
- Buffer non-seekable
Streaminputs inPdqHasher.FromStreamusingStream.CanSeekbefore callingSKCodec.Create. - Update the non-seekable stream unit test to
CompleteAsync()thePipeWriterafter writing so reads can finish.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/PdqHash/PdqHasher.cs |
Adds buffering for non-seekable streams before decoding via SkiaSharp. |
test/PdqHash.Tests/Streams/StreamParsingTests.cs |
Ensures the pipe writer completes so the reader sees EOF during hashing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@iwillspeak I've opened a new pull request, #67, to work on those changes. Once the pull request is ready, I'll request review from you. |
If the input stream is not seekable, buffer its contents into a MemoryStream to ensure compatibility with downstream processing that requires seeking.
…he pipe. This signals to the reader that no more data will be written.
Co-authored-by: iwillspeak <1004401+iwillspeak@users.noreply.github.com>
4702ca2 to
32171d3
Compare
e8c5011
This reverts commit e8c5011.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Merging this PR in order to get a Nuget package to be able to test the changes made in this PR. If changea are not effective, will revert this PR. |
Fix: Buffer non-seekable streams before passing to SkiaSharp
SkiaSharp requires a seekable stream to parse image headers and decode bitmaps. Non-seekable streams were causing SkiaSharp to fail internally.
The fix moves the buffering logic into PdqHasher.FromStream using a stream.CanSeek check — if the stream isn't seekable, it is copied into a MemoryStream (which is seekable) before being passed to SkiaSharp. Seekable streams are unaffected.
The EnsureHashingWithNonSeekableStreams unit test has been updated to call pipe.Writer.CompleteAsync() after writing, which is required for the CopyTo to receive EOF and complete.