[Pkg-javascript-commits] [node-streamsink] 01/02: Imported Upstream version 1.0.1

Andrew Kelley andrewrk-guest at moszumanska.debian.org
Fri Jun 27 22:45:01 UTC 2014


This is an automated email from the git hooks/post-receive script.

andrewrk-guest pushed a commit to branch master
in repository node-streamsink.

commit 0ee21ce0f7063bdb955027463c640b048031c44f
Author: Andrew Kelley <superjoe30 at gmail.com>
Date:   Fri Jun 27 22:40:54 2014 +0000

    Imported Upstream version 1.0.1
---
 README.md    | 13 +++++++++++++
 index.js     | 31 +++++++++++++++++++++++++++++++
 package.json | 19 +++++++++++++++++++
 test.js      | 15 +++++++++++++++
 4 files changed, 78 insertions(+)

diff --git a/README.md b/README.md
new file mode 100644
index 0000000..c173d92
--- /dev/null
+++ b/README.md
@@ -0,0 +1,13 @@
+## Usage
+
+```js
+var StreamSink = require('streamsink');
+
+var sink = new StreamSink();
+
+fs.createReadStream("foo.txt").pipe(sink);
+sink.on('finish', function() {
+  // sink has now buffered foo.txt
+  sink.createReadStream().pipe(someDestination);
+});
+```
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..ceddffa
--- /dev/null
+++ b/index.js
@@ -0,0 +1,31 @@
+var stream = require('stream');
+var util = require('util');
+
+module.exports = StreamSink;
+
+util.inherits(StreamSink, stream.Writable);
+function StreamSink(options) {
+  stream.Writable.call(this, options);
+  this.buffer = [];
+}
+
+StreamSink.prototype._write = function(chunk, encoding, callback) {
+  this.buffer.push(chunk);
+  callback();
+};
+
+StreamSink.prototype.createReadStream = function(options) {
+  var s = new stream.Readable(options);
+  s.buffer = this.buffer;
+  s._read = function(size) {
+    for (var i = 0; i < s.buffer.length; i += 1) {
+      s.push(s.buffer[i]);
+    }
+    s.push(null);
+  };
+  return s;
+};
+
+StreamSink.prototype.toString = function(arg) {
+  return this.buffer.map(function(buf) { return buf.toString(arg); }).join('');
+};
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..7c4bc61
--- /dev/null
+++ b/package.json
@@ -0,0 +1,19 @@
+{
+  "name": "streamsink",
+  "version": "1.0.1",
+  "description": "pipe to a buffer, then create readable streams from it",
+  "main": "index.js",
+  "scripts": {
+    "test": "node test.js"
+  },
+  "repository": {
+    "type": "git",
+    "url": "git://github.com/andrewrk/node-streamsink.git"
+  },
+  "author": "Andrew Kelley <superjoe30 at gmail.com>",
+  "license": "MIT",
+  "bugs": {
+    "url": "https://github.com/andrewrk/node-streamsink/issues"
+  },
+  "homepage": "https://github.com/andrewrk/node-streamsink"
+}
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..8e64b45
--- /dev/null
+++ b/test.js
@@ -0,0 +1,15 @@
+var StreamSink = require('./');
+var assert = require('assert');
+
+var sink = new StreamSink();
+sink.on('finish', function() {
+  var s = sink.createReadStream();
+  var newSink = new StreamSink();
+  newSink.on('finish', function() {
+    assert.strictEqual(newSink.toString(), "hi");
+    console.log("OK");
+  });
+  sink.createReadStream().pipe(newSink);
+});
+sink.write("hi");
+sink.end();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-streamsink.git



More information about the Pkg-javascript-commits mailing list