Class ReadableStreamBYOBRequest
- Namespace
- CSharpToJavaScript.APIs.JS
- Assembly
- CSharpToJavaScript.dll
The ReadableStreamBYOBRequest interface of the Streams API represents a "pull request" for data from an underlying source that will made as a zero-copy transfer to a consumer (bypassing the stream's internal queues).
[Value("ReadableStreamBYOBRequest")]
public class ReadableStreamBYOBRequest
- Inheritance
-
ReadableStreamBYOBRequest
- Inherited Members
Remarks
ReadableStreamBYOBRequest objects are created in "BYOB mode" when a consumer makes a request for data and the stream's internal queue is empty.
(The stream will resolve the consumer's request directly if it already has buffered data).
An underlying byte source can access active BYOB requests through its controller's ByobRequest property, which will be set to null if there is no outstanding request.
An underlying source that supports "BYOB mode" should check for ByobRequest and must use it for transferring data, if present.
If data arrives from the underlying source when ByobRequest is null, it can be queued using Enqueue(Union223).
This might happen when an underlying push source receives new data when the stream's internal buffers are not empty.
An underlying source uses the request by writing data to the BYOB request's view and then calling respond(), or by calling respondWithNewView() and passing a new view as an argument.
Note that the "new view" must actually be a view over the same buffer as the original view, starting at the same offset.
This might be used to return a shorter buffer if the underlying source is unable to fill the entire original view.
Note that a ReadableByteStreamController is only created for underlying sources when type="bytes" is specified for the source in the ReadableStream() constructor.
"BYOB mode" is enabled when either autoAllocateChunkSize is specified in the ReadableController() constructor or when using a ReadableStreamBYOBReader (typically constructed by calling GetReader(ReadableStreamGetReaderOptions) with the argument { mode: 'byob' }).
Constructors
ReadableStreamBYOBRequest()
public ReadableStreamBYOBRequest()
Properties
View
The view getter property of the ReadableStreamBYOBRequest interface returns the current view.
[Value("view")]
public Union223? View { get; }
Property Value
- Union223?
A typed array representing the destination region to which the controller can write generated data.
nullif the request has already been responded to, by calling Respond(ulong) or RespondWithNewView(Union223).
Remarks
Methods
Respond(ulong)
The respond() method of the ReadableStreamBYOBRequest interface is used to signal to the associated readable byte stream that the specified number of bytes were written into the View.
[Value("respond")]
public GlobalObject.Undefined Respond(ulong bytesWritten)
Parameters
bytesWrittenulong
Returns
Remarks
After this method is called, the ReadableStreamBYOBRequestview will be transferred and no longer modifiable.
RespondWithNewView(Union223)
The respondWithNewView() method of the ReadableStreamBYOBRequest interface specifies a new view that the consumer of the associated readable byte stream should write to instead of View.
[Value("respondWithNewView")]
public GlobalObject.Undefined RespondWithNewView(Union223 view)
Parameters
viewUnion223
Returns
Remarks
The new view must be a {{jsxref("TypedArray")}} or a {{jsxref("DataView")}} that provides a view onto the same backing memory region as View.
After this method is called, the view that was passed into the method will be transferred and no longer modifiable.
The method is intended for use cases where an underlying byte source needs to transfer a byobRequest.view internally before finishing its response.
For example, the source may transfer the BYOB view to a separate worker thread, and wait for the worker to transfer it back once it has been filled.