From cbd649df8a440e60c07d003c955b9e3668849ee4 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Sun, 18 Oct 2015 11:24:55 +0200 Subject: [PATCH] Added README. --- README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.md b/README.md index ae48dd9..6fc4063 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,7 @@ API --- * mqtt#generate() + * mqtt#writeToStream() * mqtt#parser() @@ -96,6 +97,36 @@ Generates a `Buffer` containing an MQTT packet. The object must be one of the ones specified by the [packets](#packets) section. Throws an `Error` if a packet cannot be generated. + +### mqtt.writeToStream(object, stream) + +Writes the mqtt packet defined by `object` to the given stream. +The object must be one of the ones specified by the [packets](#packets) +section. Emits an `Error` on the stream if a packet cannot be generated. + +This function is best used with `cork()` in the Streams3 API, as +follows: + +```js + +funciton send(packet, stream) { + stream.cork() + var res = mqtt.writeToStream({ + cmd: 'publish' + , topic: 'test' + , payload: buf + }, stream); + process.nextTick(uncork, stream); +} + +// this should be defined at the top +// level +function uncork (stream) { + stream.uncork() +} + +``` + ### mqtt.parser()