File tree Expand file tree Collapse file tree
test/PdqHash.Tests/Streams Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -66,7 +66,15 @@ private static void ComputeDCTMatrix(Memory<float> memory)
6666 public HashResult ? FromStream ( Stream input , string source )
6767 {
6868 var stopwatch = Stopwatch . StartNew ( ) ;
69-
69+
70+ using var bufferedStream = input . CanSeek ? null : new MemoryStream ( ) ;
71+ if ( bufferedStream != null )
72+ {
73+ input . CopyTo ( bufferedStream ) ;
74+ bufferedStream . Position = 0 ;
75+ input = bufferedStream ;
76+ }
77+
7078 using var codec = SKCodec . Create ( input , out var result ) ;
7179
7280 if ( codec == null )
Original file line number Diff line number Diff line change @@ -62,7 +62,11 @@ public async Task EnsureHashingWithNonSeekableStreams()
6262 return hasher . FromStream ( pipe . Reader . AsStream ( ) , "" ) ;
6363 } ) ;
6464
65- var writeTask = Task . Run ( ( ) => pipe . Writer . WriteAsync ( bytes ) ) ;
65+ var writeTask = Task . Run ( async ( ) =>
66+ {
67+ await pipe . Writer . WriteAsync ( bytes ) ;
68+ await pipe . Writer . CompleteAsync ( ) ;
69+ } ) ;
6670
6771 await Task . WhenAll ( hashTask , writeTask ) ;
6872
You can’t perform that action at this time.
0 commit comments