pipeStream.js

Methods

createStream(path)#

Creates readStream from a file. 'highWaterMark' determines the size of data (and payment) chunks. For audio streaming it's recommended to keep it small (2**13), since big chunks can cause errors in payment calculation. On the other hand for video streaming bigger chunks (e.g. 2**16), can speed up the stream loading.
Parameters:
NameTypeDescription
pathstringto the file
Source:

pipeMediaIntoStream(meta, stream, userId)#

Listen to file stream *readable* event for piping the data, and close the stream when no more data to be read.
Parameters:
NameTypeDescription
metaobjectstreamingFileMeta, including *pricePerByte* property
streamobjectnode.js Readable stream
userIdstring
Source:

(async) pipeStream(meta, stream, userId)#

Calculates cost of data stream chunk and pipes the stream if is able to pay that cost. Otherwise waits for new payments and retries in 400ms.
Parameters:
NameTypeDescription
metaobjectstreamingFileMeta, including *pricePerByte* property
streamobjectnode.js Readable stream
userIdstring
Source:

prepareStreamCtx(ctx, meta)#

Set request headers and longer than default timeout for wainting payments.
Parameters:
NameTypeDescription
ctxobjectnode.js request context
metaobjectstreamingFileMeta, including *fileSize* and *mime* properties
Source: