Read a stream

To read a stream on-chain, use its payload_transaction_id

let content;

(async() => {

    const options = { 
        onGetHistoricalData: (previous_data) => { content = previous_data; },                      
        onData: (data) => { content += data; },  
        onFinish: (result) => { console.log(result); }        
        onError: (error) => { console.log(error); }
    }
    const reader = new StreamnoteReader(
        "G3RINZEJDP2UCPKHEFRL5DRPIYC45PSOYYTDON3JA6NRPEJKFBJA", 
        options
    );    
    
    console.log(await reader.getPayload());
       
    if(await reader.isOver()){    
        console.log("The stream is over");
    }
    
    reader.start(); 
});

Constructor

Name
Description
Type

payload_transaction_id

The payload_transaction_id of the stream to read

string

options

See the options table below

object

Options

Name
Description
Type

password

The password to decrypt the stream if required.

string

aes_key

The AES key to decrypt the stream if required.

string

GetHistoricalData

⇒ (historical_data)

A callback that provides all the data sent since the start of the stream.

function

onData

⇒ (data)

The callback that retrieves new incoming data as it arrives.

function

onFinish

⇒ ()

The callback triggered when the stream ends.

function


Methods

circle-info

Note: getPayload() and isOver() can be used without passing any options to the StreamnoteReader constructor. Even if the stream is encrypted (with a password or an AES key), no decryption information is needed to check whether the stream has finished or to retrieve its payload.

start

Start reading the stream. Incoming data will start being delivered through the onData(data) callback.

Return

null


getPayload

Return

A promise that contains the stream's payload.


getHistoricalData

Return

A promise that contains all the data sent since the start of the stream.


isOver

Return

A promise that resolves to a boolean indicating whether the stream has ended.

Last updated