obj-stream
v0.0.26
Published
simple object streams
Downloads
13
Readme
A lightweight object stream library for NodeJS and the browser.
var stream = require("obj-stream");
var stream = new stream.Stream();
stream.write({ name: "obj" }); // valid
stream.write("blah"); // invalid
stream.end();
var readable = new stream.Readable([{ name: "obj" }]);
readable.pipe(new stream.Stream());
writable stream.writable()
creates a new writable stream
var writable = stream.writable();
writable.write(object)
Writes a new object
writable.write({ name: "Jeff Gordon" });
writable.end([object])
Ends the stream
writable.write({ name: "Donkay" });
writable.write({ name: "Shrek" });
writable.end(); // done
writable.once(event, callback)
listens to one event then disposes
reader writable.reader
Returns the readable object
var writer = stream.writable();
var reader = writer.reader;
reader.on("data", function() {
});
reader.on("end", function() {
});
writer.end({ name: "Oprah" }); // write & end
reader stream.readable()
creates a new readable object
reader.on(event, callback)
listens for an event.
event
error
- emitted on errordata
- emitted on dataend
- emitted when the stream closesdrain
- emitted when the writer is resumed
reader.once(event, callback)
listens to one event then disposes
reader.removeListener(event, callback)
removes a listener
reader.pause()
pauses the stream.
var writer = stream.writable();
var reader = writer.reader;
reader.pause();
writer.write({ name: "bob" }); // buffered, doesn't get emitted as data
reader.resume()
resumes the stream.
reader.isPaused()
returns true if the stream is paused.
writable.pipe(writable)
pipes data to a writable
stream stream.through(fn)
helper for transforming data
var writable = stream.writable();
writable.reader.pipe(stream.though(function(data, next) {
this.push("blah");
next(); // done
})).on("data", function(data) {
// blah is always emitted here
});
writable.write({ name: "org" });
writable.end();