static async Task Core(string path, byte[] bytes, CancellationToken cancellationToken) { #if MS_IO_REDIST using FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, 1, FileOptions.Asynchronous | FileOptions.SequentialScan); await fs.WriteAsync(bytes, 0, bytes.Length, cancellationToken).ConfigureAwait(false); #else using SafeFileHandle sfh = OpenHandle(path, FileMode.Create, FileAccess.Write, FileShare.Read, FileOptions.Asynchronous | FileOptions.SequentialScan); await RandomAccess.WriteAtOffsetAsync(sfh, bytes, 0, cancellationToken).ConfigureAwait(false); #endif }
public override ValueTask WriteAsync(ReadOnlyMemory <byte> source, CancellationToken cancellationToken) { if (!CanWrite) { ThrowHelper.ThrowNotSupportedException_UnwritableStream(); } long filePositionBefore = -1; if (CanSeek) { filePositionBefore = _filePosition; _filePosition += source.Length; } return(RandomAccess.WriteAtOffsetAsync(_fileHandle, source, filePositionBefore, cancellationToken)); }