Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated module to conform to >= NodeJS v6.0.0 standards. #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
489 changes: 489 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"mocha": true,
"freeze": true,
"browserify": true,
"strict": true,
"worker": true,
"scripturl": true,
"latedef": "nofunc",
"onevar": true,
"node": true,
"maxstatements": 25,
"futurehostile": true,
"noarg": true,
"unused": true,
"esnext": true,
"eqeqeq": true,
"nocomma": true,
"devel": true,
"maxdepth": 5,
"jquery": true,
"browser": true,
"debug": true,
"maxparams": 5,
"undef": true,
"globalstrict": true,
"maxcomplexity": 20,
"typed": true,
"nonew": true,
"forin": false,
"shadow": true,
"nocomma": false
}
9 changes: 7 additions & 2 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
v0.2.0 (29 Sept 2016)
Updated to >= v6.0.0 format.
Simplified structure.
Clean up.

v0.1.1 (03 Apr 2015)
Clean up.
Clean up.

v0.1.0 (21 Oct 2013)
Performance slightly improved due to the simplification of the code. This is
Expand All @@ -11,4 +16,4 @@ v0.0.2 (19 Jul 2013)
Bump version.

v0.0.1 (01 Apr 2013)
First release.
First release.
4 changes: 3 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ The MIT License (MIT)

Copyright (c) 2014 Gabriel Llamas

Contributor 2016 Nick Soggin

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
Expand All @@ -18,4 +20,4 @@ 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.
THE SOFTWARE.
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,24 @@ streamifier

[![npm][npm-image]][npm-url]

<a name="createReadStream"></a>
___module_.createReadStream(object[, options]) : Readable__
Makes a [createReadStream][0] from a [Buffer][1]

A common solution for writing a buffer to file, then creating a read stream from that file path.

Usage:
```js
const streamifier = require( 'streamifier' ).createReadStream;

streamifier( data ).pipe( process.stdout );
```

Returns a Readable stream.

The `object` can be of any data type. If it is a Buffer or a string, the available `options` are [`highWaterMark` and `encoding`](http://nodejs.org/api/stream.html#stream_new_stream_readable_options), otherwise the Readable stream is automatically set in [object mode](http://nodejs.org/api/stream.html#stream_object_mode) and the `options` parameter is ignored.
The `object` can be of any data type. If it is a Buffer or a string, the available `options` are [`highWaterMark` and `encoding`][2], otherwise the Readable stream is automatically set in [object mode][3] and the `options` parameter is ignored.

[npm-image]: https://img.shields.io/npm/v/streamifier.svg?style=flat
[npm-url]: https://npmjs.org/package/streamifier
[npm-url]: https://npmjs.org/package/streamifier
[0]: https://nodejs.org/api/fs.html#fs_fs_createreadstream_path_options
[1]: https://nodejs.org/api/buffer.html
[2]: http://nodejs.org/api/stream.html#stream_new_stream_readable_options
[3]: http://nodejs.org/api/stream.html#stream_object_mode
4 changes: 2 additions & 2 deletions examples/buffer-stream.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var streamifier = require('../lib');
var streamifier = require('../');

streamifier.createReadStream(new Buffer ([97, 98, 99])).pipe(process.stdout);
// abc
// abc
4 changes: 2 additions & 2 deletions examples/object-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var stream = require('stream');
var util = require('util');
var streamifier = require('../lib');
var streamifier = require('../');

/**
* Since a readable stream in object mode cannot be piped to a writable stream
Expand All @@ -26,4 +26,4 @@ JSONStringifier.prototype._transform = function (obj, encoding, cb) {
streamifier.createReadStream({ a: 1, b: 2 })
.pipe(new JSONStringifier ())
.pipe(process.stdout);
// {'a':1,'b':2}
// {'a':1,'b':2}
4 changes: 2 additions & 2 deletions examples/string-stream.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var streamifier = require('../lib');
var streamifier = require('../');

streamifier.createReadStream('abc').pipe(process.stdout);
// abc
// abc
29 changes: 29 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const stream = require( 'stream' );

class ReadStream extends stream.Readable
{
constructor( obj, opt = {} )
{
super();
if( Buffer.isBuffer( obj ) || obj === ''+obj )
stream.Readable.call( this, {
highWaterMark: opt.highWaterMark, encoding: opt.encoding
} );
else
stream.Readable.call( this, { objectMode: true } );
this._object = obj;
this.init();
}

init()
{
ReadStream.prototype._read = () => {
this.push( this._object );
this._object = null;
};
}
}

module.exports.createReadStream = ( obj, opt ) => new ReadStream( obj, opt );
28 changes: 0 additions & 28 deletions lib/index.js

This file was deleted.

11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
{
"name": "streamifier",
"version": "0.1.1",
"version": "0.2.0",
"description": "Converts a Buffer/String into a readable stream",
"keywords": [
"string",
"buffer",
"readable",
"stream"
],
"author": "Gabriel Llamas <[email protected]>",
"author": [
"Gabriel Llamas <[email protected]>",
"Nick Soggin <[email protected]>"
],
"repository": "git://github.com/gagle/node-streamifier.git",
"engines": {
"node": ">=0.10"
},
"license": "MIT",
"main": "lib"
}
"main": "index.js"
}