Skip to content
Browse files

initial

  • Loading branch information...
0 parents commit 5aa635a60f3a616c3680ede3b1d2f70d2542e9bc @joeferner joeferner committed
Showing with 71 additions and 0 deletions.
  1. +8 −0 .gitignore
  2. 0 README.md
  3. +14 −0 package.json
  4. +29 −0 pullstream.js
  5. +20 −0 test/pullStreamTest.js
8 .gitignore
@@ -0,0 +1,8 @@
+/build/*
+node_modules
+*.node
+*.sh
+*.swp
+.lock*
+npm-debug.log
+.idea
0 README.md
No changes.
14 package.json
@@ -0,0 +1,14 @@
+{
+ "name": "pullstream",
+ "version": "0.0.1",
+ "description": "A stream you can pull data from.",
+ "main": "pullstream.js",
+ "scripts": {
+ "test": "./node_modules/.bin/tap --stderr ./test/"
+ },
+ "license": "MIT",
+ "devDependencies": {
+ "tap": "~0.3.0",
+ "stream-buffers": "~0.2.3"
+ }
+}
29 pullstream.js
@@ -0,0 +1,29 @@
+'use strict';
+
+module.exports = PullStream;
+
+var inherits = require("util").inherits;
+var Stream = require('stream').Stream;
+
+function PullStream() {
+ Stream.apply(this);
+ this.readable = false;
+ this.writable = true;
+}
+inherits(PullStream, Stream);
+
+PullStream.prototype.write = function (data) {
+ this.process(data, false);
+};
+
+PullStream.prototype.end = function (data) {
+ this.process(data, true);
+};
+
+PullStream.prototype.process = function (data, end) {
+ if (end) {
+ this.emit('end');
+ }
+};
+
+
20 test/pullStreamTest.js
@@ -0,0 +1,20 @@
+'use strict';
+
+var test = require('tap').test;
+var streamBuffers = require("stream-buffers");
+var PullStream = require('../');
+
+test("source sending 1-byte at a time", function (t) {
+ var ps = new PullStream();
+ ps.on('end', function () {
+ t.end();
+ });
+
+ var sourceStream = new streamBuffers.ReadableStreamBuffer({
+ frequency: 0,
+ chunkSize: 1
+ });
+
+ sourceStream.pipe(ps);
+});
+

0 comments on commit 5aa635a

Please sign in to comment.
Something went wrong with that request. Please try again.