Permalink
Browse files

first

  • Loading branch information...
0 parents commit 4e038c15c10defdb5361a4068c58d2866a3bbd11 @Raynos committed Aug 24, 2012
@@ -0,0 +1,3 @@
+node_modules
+*.log
+*.err
19 LICENCE
@@ -0,0 +1,19 @@
+Copyright (c) 2012 Raynos.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
No changes.
@@ -0,0 +1,33 @@
+# buffer-stream
+
+A duplex stream that buffers writes
+
+## Example
+
+``` js
+var BufferStream = require("buffer-streams")
+
+var buffer = BufferStream().buffer()
+
+buffer.write("stuff")
+
+buffer.on("data", doStuff)
+
+someTimeLater(function (stream) {
+ // Oh we have a stream
+ // Empty the buffer onto the stream
+ // Further writes to the buffer go directly to the stream
+ // Any data the stream emits get's re-emitted on the buffer
+ buffer.empty(stream)
+})
+```
+
+## Installation
+
+`npm install buffer-stream`
+
+## Contributors
+
+ - Raynos
+
+## MIT Licenced
@@ -0,0 +1,32 @@
+var BufferStream = require("../index")
+ , through = require("through")
+
+var buffer = BufferStream().buffer()
+
+setInterval(function () {
+ buffer.write("echo " + new Date().toString())
+}, 1000)
+
+buffer.on("data", function (echo) {
+ console.log("[ECHO]", echo)
+})
+
+setTimeout(setUpShakyStream, 3000)
+
+function setUpShakyStream() {
+ var shaky = through()
+
+ buffer.empty(shaky, {
+ end: false
+ })
+
+ setTimeout(killShakyStream, 3000)
+
+ function killShakyStream() {
+ buffer.buffer()
+
+ shaky.end()
+
+ setTimeout(setUpShakyStream, 3000)
+ }
+}
@@ -0,0 +1,30 @@
+var PauseStream = require("pause-stream")
+ , duplexer = require("duplexer")
+
+module.exports = BufferStream
+
+function BufferStream() {
+ var writable = PauseStream()
+ , readable = PauseStream()
+ , buffered = duplexer(writable, readable)
+
+ buffered.buffer = buffer
+ buffered.empty = empty
+
+ return buffered
+
+ function buffer() {
+ writable.pause()
+ return buffered
+ }
+
+ function empty(stream, options) {
+ if (stream) {
+ options = options || {}
+ writable.pipe(stream).pipe(readable, options)
+ }
+
+ writable.resume()
+ return buffered
+ }
+}
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 4e038c1

Please sign in to comment.