Table of Contents

Method WriteAsync

Namespace
DotNetBrowser.Net
Assembly
DotNetBrowser.dll

WriteAsync(UrlRequestJob, Stream, CancellationToken, int)

Reads all bytes from stream and writes them to the URL request job asynchronously.

public static Task WriteAsync(this UrlRequestJob job, Stream stream, CancellationToken cancellationToken = default, int bufferSize = 81920)

Parameters

job UrlRequestJob

The URL request job to write the data to.

stream Stream

The stream to read the data from.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

bufferSize int

The size of the buffer used to read the stream. Must be greater than zero.

Returns

Task

A Task that represents the asynchronous write operation.

Remarks

The stream is read in chunks to avoid buffering the entire content in memory. The calling thread is released while waiting for each chunk to be sent to the browser engine, making this method suitable for use inside Task.Run or async handlers.

After all data is written, call Complete() or Fail() to finish the request.

Exceptions

ArgumentNullException

job or stream is null.

ArgumentOutOfRangeException

bufferSize is less than or equal to zero, or greater than MaxValue - 56.