import StreamRequest from 'foglet-core/src/network/communication/stream/stream-request.js'
StreamRequest
Extends:
A StreamRequest enable to stream data to a peer using a push-based API.
Example:
const foglet = getSomeFoglet();
const peerID = getSomePeerID();
const stream = foglet.streamUnicast(peerID);
stream.write('Hello');
stream.write(' world!');
stream.end();
Constructor Summary
Public Constructor | ||
public |
constructor(send: function) Constructor |
Member Summary
Private Members | ||
private |
_id: * |
|
private |
_last_id: * |
|
private |
_send: * |
|
private |
_trailers: *[] |
Method Summary
Public Methods | ||
public |
addTrailer(value: *): void Add a trailer. |
|
public |
Destroy the stream and emit an error on the |
Private Methods | ||
private |
_final(callback: *) Send trailers if presents & close the transmission |
|
private |
_write(msg: *, encoding: *, callback: *): * |
Public Constructors
Private Members
private _id: * source
private _last_id: * source
private _send: * source
private _trailers: *[] source
Public Methods
public addTrailer(value: *): void source
Add a trailer.
All trailers will be sent after the stream is closed, so this method can be called ny number of times
before the end
method is called.
Params:
Name | Type | Attribute | Description |
value | * | The trailing data |
Return:
void |
public destroy(error: string) source
Destroy the stream and emit an error on the error
event.
This error will be propagated to peer(s) that which data was streamed, and the associated output stream
will also be destroyed.
Params:
Name | Type | Attribute | Description |
error | string | The error responsible for the stream's destruction |
Private Methods
private _final(callback: *) source
Send trailers if presents & close the transmission
Params:
Name | Type | Attribute | Description |
callback | * |
private _write(msg: *, encoding: *, callback: *): * source
Params:
Name | Type | Attribute | Description |
msg | * | ||
encoding | * | ||
callback | * |
Return:
* |