Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
joeferner committed Aug 8, 2012
0 parents commit 5aa635a
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
@@ -0,0 +1,8 @@
/build/*
node_modules
*.node
*.sh
*.swp
.lock*
npm-debug.log
.idea
Empty file added README.md
Empty file.
14 changes: 14 additions & 0 deletions 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 changes: 29 additions & 0 deletions 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 changes: 20 additions & 0 deletions 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.