Home Reference Source
public class | source

StreamRequest

Extends:

* → StreamRequest

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

Member Summary

Private Members
private

_id: *

private
private

_send: *

private

_trailers: *[]

Method Summary

Public Methods
public

addTrailer(value: *): void

Add a trailer.

public

destroy(error: string)

Destroy the stream and emit an error on the error event.

Private Methods
private

_final(callback: *)

Send trailers if presents & close the transmission

private

_write(msg: *, encoding: *, callback: *): *

Public Constructors

public constructor(send: function) source

Constructor

Params:

NameTypeAttributeDescription
send function

Function called to send a message

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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
error string

The error responsible for the stream's destruction

Private Methods

private _final(callback: *) source

Send trailers if presents & close the transmission

Params:

NameTypeAttributeDescription
callback *

private _write(msg: *, encoding: *, callback: *): * source

Params:

NameTypeAttributeDescription
msg *
encoding *
callback *

Return:

*