Skip to content

Commit

Permalink
Added README.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Oct 18, 2015
1 parent 3d5c79d commit cbd649d
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ API
---
* <a href="#generate"><code>mqtt#<b>generate()</b></code></a>
* <a href="#writeToStream"><code>mqtt#<b>writeToStream()</b></code></a>
* <a href="#parser"><code>mqtt#<b>parser()</b></code></a>
<a name="generate">
Expand All @@ -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.
<a name="writeToStream">
### 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()
}

```
<a name="parser">
### mqtt.parser()
Expand Down

0 comments on commit cbd649d

Please sign in to comment.