Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
schnittstabil committed Jul 5, 2014
0 parents commit 096696e
Show file tree
Hide file tree
Showing 11 changed files with 429 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# Deployed apps should consider commenting this line out:
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
node_modules

.coveralls.yml
stream-recorder-*.*.*.tgz
12 changes: 12 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"preset": "google",

"requireParenthesesAroundIIFE": true,
"maximumLineLength": 80,
"validateLineBreaks": "LF",
"validateIndentation": 2,

"disallowKeywords": ["with"],
"disallowSpacesInsideObjectBrackets": null,
"disallowImplicitTypeConversion": ["string"]
}
93 changes: 93 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"globals": {
/* expect.js */
"expect": true,

/* mocha */
"after": true,
"afterEach": true,
"before": true,
"beforeEach": true,
"describe": true,
"it": true
},

/* Enforcing options */
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"es3": true,
"forin": true,
"freeze": true,
"immed": true,
"indent": 2,
"latedef": true,
"newcap": true,
"noarg": true,
"noempty": true,
"nonbsp": true,
"nonew": true,
"plusplus": false,
"quotmark": "single",
"undef": true,
"unused": true,
"strict": true,
"trailing": true,
"maxparams": 8,
"maxdepth": 3,
"maxstatements": 20,
"maxcomplexity": 10,
"maxlen": 80,

/* Relaxing options */
"asi": false,
"boss": false,
"debug": false,
"eqnull": false,
"esnext": true,
"evil": false,
"expr": false,
"funcscope": false,
"gcl": false,
"globalstrict": false,
"iterator": false,
"lastsemic": false,
"laxbreak": false,
"laxcomma": false,
"loopfunc": false,
"maxerr": 100,
"moz": false,
"multistr": false,
"notypeof": false,
"proto": false,
"scripturl": false,
"smarttabs": false,
"shadow": false,
"sub": false,
"supernew": false,
"validthis": false,
"noyield": false,

/* Environments */
"browser": false,
"couch": false,
"devel": false,
"dojo": false,
"jquery": false,
"mootools": false,
"node": true,
"nonstandard": false,
"phantom": false,
"prototypejs": false,
"rhino": false,
"worker": false,
"wsh": false,
"yui": false,

/* Legacy */
"nomen": false,
"onevar": true,
"passfail": false,
"white": false
}
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: node_js
node_js:
- "0.11"
- "0.10"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014 Michael Mayer

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.
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# stream-recorder [![Dependencies Status Image](https://gemnasium.com/schnittstabil/stream-recorder.svg)](https://gemnasium.com/schnittstabil/stream-recorder) [![Build Status Image](https://travis-ci.org/schnittstabil/stream-recorder.svg)](https://travis-ci.org/schnittstabil/stream-recorder) [![Coverage Status](https://coveralls.io/repos/schnittstabil/stream-recorder/badge.png)](https://coveralls.io/r/schnittstabil/stream-recorder)

A stream, collecting all chunks passed through.

## Usage

Install using:

```bash
npm install --save
```

Then pipe through a recorder instance and retrieve the data:
```Javascript
var Recorder = require('stream-recorder'),
PassThrough = require('stream').PassThrough,
opts = {objectMode: true},
pre = new PassThrough(opts),
recorder = new Recorder(opts),
post = new PassThrough(opts);

post.on('finish', function() {
console.log(recorder.data);
});

pre.pipe(recorder).pipe(post);

pre.write('foo');
pre.write(1);
pre.write({ foobar: 'foobar', answer: 42 });
pre.write('bar');
pre.end();

// switch into flowing-mode
post.resume();

/*
* Output:
*
* [ 'foo', 1, { foobar: 'foobar', answer: 42 }, 'bar' ]
*/
```

## API

### Class: StreamRecorder

Stream recorders are [Transform](http://nodejs.org/api/stream.html#stream_class_stream_transform) streams.

#### new StreamRecorder([options])

* _options_ `Object` passed through [new stream.Transform([options])](http://nodejs.org/api/stream.html#stream_new_stream_transform_options)

#### StreamRecorder.data

Array of chunks (`Buffer | String | Object`) passed through, see [transform._transform](http://nodejs.org/api/stream.html#stream_transform_transform_chunk_encoding_callback) for details.

## License

Copyright (c) 2014 Michael Mayer

Licensed under the MIT license.
36 changes: 36 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';
var gulp = require('gulp'),
istanbul = require('gulp-istanbul'),
jscs = require('gulp-jscs'),
jshint = require('gulp-jshint'),
mocha = require('gulp-mocha'),
scripts = ['**/*.js', '!node_modules/**', '!coverage/**'];

gulp.task('lint', function() {
return gulp.src(scripts)
/* hint */
.pipe(jshint())
.pipe(jshint.reporter())
.pipe(jshint.reporter('fail'))
/* jscs */
.pipe(jscs());
});

gulp.task('coverage', function (done) {
gulp.src(scripts)
.pipe(istanbul())
.on('finish', function () {
/* tests */
gulp.src(['test/**/*.js'])
.pipe(mocha({
reporter: 'dot',
timeout: 100000
}))
.pipe(istanbul.writeReports({
reporters: ['lcovonly', 'text-summary']
}))
.on('end', done);
});
});

gulp.task('default', ['lint', 'coverage']);
35 changes: 35 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';
var Transform = require('readable-stream/transform'),
inherits = require('util').inherits;

function StreamRecorder(options) {
if (!(this instanceof StreamRecorder)) {
return new StreamRecorder(options);
}
options = options || {};

Transform.call(this, options);
this.objectMode = options.objectMode;

if (this.objectMode) {
this.data = [];
} else {
this.data = new Buffer('', options.encoding);
}
}
inherits(StreamRecorder, Transform);

StreamRecorder.prototype._transform = function(chunk, encoding, done) {
if (this.objectMode) {
this.data.push(chunk);
} else {
if (typeof chunk === 'string') {
chunk = new Buffer(chunk, encoding);
}
this.data = Buffer.concat([this.data, chunk]);
}
this.push(chunk, encoding);
done();
};

module.exports = StreamRecorder;
44 changes: 44 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "stream-recorder",
"version": "0.1.0",
"description": "A stream, collecting all chunks passed through",
"main": "index.js",
"scripts": {
"test": "./node_modules/gulp/bin/gulp.js && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
},
"repository": {
"type": "git",
"url": "https://github.com/schnittstabil/stream-recorder.git"
},
"keywords": [
"passthrough",
"stream",
"record",
"collect",
"gulpfriendly"
],
"author": "Michael Mayer <michael@schnittstabil.de> (https://github.com/schnittstabil)",
"license": "MIT",
"bugs": {
"url": "https://github.com/schnittstabil/stream-recorder/issues"
},
"homepage": "https://github.com/schnittstabil/stream-recorder",
"engines": {
"node": "^0.11 || ^0.10"
},
"files": [
"index.js"
],
"devDependencies": {
"coveralls": "^2.11.0",
"expect.js": "^0.3.1",
"gulp": "^3.8.5",
"gulp-istanbul": "^0.2.0",
"gulp-jscs": "^0.6.0",
"gulp-jshint": "^1.6.4",
"gulp-mocha": "^0.4.1"
},
"dependencies": {
"readable-stream": "^1.0.27-1"
}
}
Loading

0 comments on commit 096696e

Please sign in to comment.