Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial

  • Loading branch information...
commit 5aa635a60f3a616c3680ede3b1d2f70d2542e9bc 0 parents
@joeferner joeferner authored
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);
+});
+
Please sign in to comment.
Something went wrong with that request. Please try again.