firebase and back
Pipe tofirebase-stream
allows you to pipe any Node.js stream
to a database node in google's firebase and read its data back as stream.
Usage
Install the library
$ npm install --save firebase>3 firebase-stream
then you may use it like in the following example:
// ------------- SETUP ------------const firebase = const app = firebase// Keep the db reference if you want to later disconnect from itconst db = app // In order to keep a clean database, lets have a namespace forconst dbRef = db // ------------- WRITING ------------ // This will not work if you don't call `npm install firebase-stream` if you didn't do so already!const stream = const output = stream // Write something to the outstreamoutput // ------------- READING ------------ // Create a new stream that reads from the same database nodeconst input = stream// Receive the data sent to firebaseinputinput
API
const stream = stream
Binary Modes
By default data sent through the stream is stored as utf8 strings. This should
mostly work just fine (even with binary data). The reason for this is because
big integer arrays do not perform well in firebase. Setting the binary
options
will store the data as integer Array.
Data Structure
The reference passed-in to the stream will not be written to.
Instead firebase-stream
will create two children
: finished
and buffer
.
finished
will be either true
or false
, depending if the stream is finished
or not. buffer
will contain a list of children that each contains one "chunk"
field and a time
field. The first entry with null
as data
terminates the stream.