Created
December 23, 2021 03:54
-
-
Save neuecc/21b98b71074828e246d384eb2568a559 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static async Task ReadFromAsync(NativeMemoryArray<byte> buffer, Stream stream, CancellationToken cancellationToken = default) | |
| { | |
| var writer = buffer.CreateBufferWriter(); | |
| int read; | |
| while ((read = await stream.ReadAsync(writer.GetMemory(), cancellationToken).ConfigureAwait(false)) != 0) | |
| { | |
| writer.Advance(read); | |
| } | |
| } | |
| public static async Task WriteToAsync(NativeMemoryArray<byte> buffer, Stream stream, CancellationToken cancellationToken = default) | |
| { | |
| foreach (var item in buffer.AsMemorySequence()) | |
| { | |
| await stream.WriteAsync(item, cancellationToken); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment