@@ -123,6 +123,11 @@ public override void Write(byte[] buffer, int offset, int count)
123123 throw new NotSupportedException ( ) ;
124124 }
125125
126+ public override ValueTask WriteAsync ( ReadOnlyMemory < byte > buffer , CancellationToken cancellationToken = default )
127+ {
128+ throw new NotSupportedException ( ) ;
129+ }
130+
126131 public override Task WriteAsync ( byte [ ] buffer , int offset , int count , CancellationToken cancellationToken )
127132 {
128133 throw new NotSupportedException ( ) ;
@@ -207,7 +212,10 @@ public override int Read(byte[] buffer, int offset, int count)
207212 return UpdatePosition ( read ) ;
208213 }
209214
210- public override async Task < int > ReadAsync ( byte [ ] buffer , int offset , int count , CancellationToken cancellationToken )
215+ public override Task < int > ReadAsync ( byte [ ] buffer , int offset , int count , CancellationToken cancellationToken )
216+ => ReadAsync ( buffer . AsMemory ( offset , count ) , cancellationToken ) . AsTask ( ) ;
217+
218+ public override async ValueTask < int > ReadAsync ( Memory < byte > buffer , CancellationToken cancellationToken )
211219 {
212220 if ( _finished )
213221 {
@@ -231,7 +239,9 @@ public override async Task<int> ReadAsync(byte[] buffer, int offset, int count,
231239 if ( matchOffset > bufferedData . Offset )
232240 {
233241 // Sync, it's already buffered
234- read = _innerStream . Read ( buffer , offset , Math . Min ( count , matchOffset - bufferedData . Offset ) ) ;
242+ var slice = buffer [ ..Math . Min ( buffer . Length , matchOffset - bufferedData . Offset ) ] ;
243+
244+ read = _innerStream . Read ( slice . Span ) ;
235245 return UpdatePosition ( read ) ;
236246 }
237247
@@ -259,7 +269,7 @@ public override async Task<int> ReadAsync(byte[] buffer, int offset, int count,
259269 }
260270
261271 // No possible boundary match within the buffered data, return the data from the buffer.
262- read = _innerStream . Read ( buffer , offset , Math . Min ( count , bufferedData . Count ) ) ;
272+ read = _innerStream . Read ( buffer . Span [ .. Math . Min ( buffer . Length , bufferedData . Count ) ] ) ;
263273 return UpdatePosition ( read ) ;
264274 }
265275
0 commit comments