package/package.json000644 000765 000024 0000001517 12560170354013024 0ustar00000000 000000 { "name": "callback-stream", "version": "1.1.0", "description": "A pipeable stream that calls your callback", "main": "index.js", "scripts": { "lint": "standard", "test": "./node_modules/.bin/tap test.js" }, "precommit": ["lint", "test"], "website": "https://github.com/mcollina/callback-stream", "repository": { "type": "git", "url": "https://github.com/mcollina/callback-stream.git" }, "bugs": { "url": "http://github.com/mcollina/callback-stream/issues" }, "keywords": [ "callback", "stream" ], "author": "Matteo Collina ", "license": "MIT", "dependencies": { "inherits": "^2.0.1", "readable-stream": "> 1.0.0 < 3.0.0" }, "devDependencies": { "pre-commit": "^1.1.1", "standard": "^5.0.0", "tap": "~0.4.2", "tape": "^4.0.2" } } package/.npmignore000644 000765 000024 0000000114 12535510077012527 0ustar00000000 000000 node_modules/ build/ libleveldb.so libleveldb.a test-data/ _benchdb_* *.sw* package/README.md000644 000765 000024 0000005156 12560170326012017 0ustar00000000 000000 CallbackStream ===== [![Build Status](https://travis-ci.org/mcollina/callback-stream.png)](https://travis-ci.org/mcollina/callback-stream) It is a safe variant of the [concat-stream](https://github.com/maxogden/node-concat-stream) package that _will always return an array_. It does everything callback-stream does, minus the concatenation. In fact, it just callbacks you with an array containing your good stuff. It is based on the Stream 2 API, but it also works on node v0.8. It also support Stream 3, which is bundled with node v0.12 and iojs. ## Installation ``` npm install callback-stream --save ``` ## Pipe usage ```js var callback = require('callback-stream') var fs = require('fs') var read = fs.createReadStream('readme.md') var write = callback(function (err, data) { console.log(err, data) }) read.pipe(write) ``` ## Object mode usage ``` var callback = require('callback-stream') var write = callback.obj(function (err, data) { // this will print ['hello', 'world'] console.log(data) }) write.write('hello') write.write('world') write.end() ``` ## Contributing to CallbackStream * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it * Fork the project * Start a feature/bugfix branch * Commit and push until you are happy with your contribution * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally. ## LICENSE - "MIT License" Copyright (c) 2013-2015 Matteo Collina, http://matteocollina.com 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. package/index.js000644 000765 000024 0000001762 12560170120012174 0ustar00000000 000000 'use strict' var Writable = require('readable-stream').Writable var inherits = require('inherits') function CallbackStream (options, callback) { if (!(this instanceof CallbackStream)) { return new CallbackStream(options, callback) } if (typeof options === 'function') { callback = options options = {} } Writable.call(this, options) this.results = [] this.callback = callback this.on('finish', deliversCallback) this.once('pipe', handlePipe) } function deliversCallback () { this.callback(null, this.results) } function handlePipe (source) { source.on('error', this.callback) } inherits(CallbackStream, Writable) CallbackStream.prototype._write = function (data, encoding, done) { this.results.push(data) done() } CallbackStream.obj = function (options, callback) { if (typeof options === 'function') { callback = options options = {} } options.objectMode = true return new CallbackStream(options, callback) } module.exports = CallbackStream package/test.js000644 000765 000024 0000003006 12560170022012036 0ustar00000000 000000 'use strict' var test = require('tap').test var callback = require('./') var fs = require('fs') test('call the callback after end with object mode', function (t) { var opts = { objectMode: true } var stream = callback(opts, function (err, results) { t.deepEqual(results, ['hello'], 'should return the ending value') t.end() }) stream.end('hello') }) test('support multiple writes with object mode', function (t) { var opts = { objectMode: true } var stream = callback(opts, function (err, results) { t.deepEqual(results, ['hello', 'world'], 'should return the ending value') t.end() }) stream.write('hello') stream.end('world') }) test('works without object mode', function (t) { var stream = callback(function (err, results) { t.equal(results.length, 1, 'should contain only one value') t.deepEqual(results[0].toString(), 'world', 'should return the ending value') t.end() }) stream.end('world') }) test('is pipeable', function (t) { var write = callback(function (err, results) { var actual = Buffer.concat(results).toString() var expected = fs.readFileSync('README.md').toString() t.equal(actual, expected, 'should have the same content of the file') t.end() }) var read = fs.createReadStream('README.md') read.pipe(write) }) test('callback.obj shortcut for objectMode', function (t) { var stream = callback.obj(function (err, results) { t.deepEqual(results, ['hello'], 'should return the ending value') t.end() }) stream.end('hello') }) package/.jshintrc000644 000765 000024 0000002212 12535510077012356 0ustar00000000 000000 { "predef": [ ] , "bitwise": false , "camelcase": false , "curly": false , "eqeqeq": false , "forin": false , "immed": false , "latedef": false , "noarg": true , "noempty": true , "nonew": true , "plusplus": false , "quotmark": true , "regexp": false , "undef": true , "unused": true , "strict": false , "trailing": true , "maxlen": 120 , "asi": true , "boss": true , "debug": true , "eqnull": true , "es5": true , "esnext": true , "evil": true , "expr": true , "funcscope": false , "globalstrict": false , "iterator": false , "lastsemic": true , "laxbreak": true , "laxcomma": true , "loopfunc": true , "multistr": false , "onecase": false , "proto": false , "regexdash": false , "scripturl": true , "smarttabs": false , "shadow": false , "sub": true , "supernew": false , "validthis": true , "browser": true , "couch": false , "devel": false , "dojo": false , "mootools": false , "node": true , "nonstandard": true , "prototypejs": false , "rhino": false , "worker": true , "wsh": false , "nomen": false , "onevar": true , "passfail": false }package/.travis.yml000644 000765 000024 0000000056 12535510077012646 0ustar00000000 000000 language: node_js node_js: - 0.8 - "0.10"