diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..21638b2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,489 @@ +# code coverage +coverage +lib-cov +test-results.xml +clover.xml + +# editor and that .tmp file +.idea +.tmp + +# Node logs +npm-debug.log* +logs +*.log +pids +*.pid +*.seed + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules +jspm_packages + +# Optional npm cache directory +.npm + +# Optional REPL history +.node_repl_history + +# Yeoman/bow/&c. +bower_components/ +build/ +dist/ + +# Linux ignores +*~ +.fuse_hidden +.directory +.Trash-* + +## JetBrains file-based project format: +*.iws + +# perl, you crazy old thing, you... +/blib/ +/.build/ +_build/ +cover_db/ +inc/ +Build +!Build/ +Build.bat +.last_cover_stats +/Makefile +/Makefile.old +/MANIFEST.bak +/META.yml +/META.json +/MYMETA.* +nytprof.out +/pm_to_blib +*.o +*.bs +/_eumm/ + +# SASS +.sass-cache/ +*.css.map + +# Unity 3D +/[Ll]ibrary/ +/[Tt]emp/ +/[Oo]bj/ +/[Bb]uild/ +/[Bb]uilds/ +/Assets/AssetStoreTools* + +# Autogenerated VS/MD solution and project files +ExportedObj/ +*.csproj +*.unityproj +*.sln +*.suo +*.tmp +*.user +*.userprefs +*.pidb +*.booproj +*.svd + + +# Unity3D generated meta files +*.pidb.meta + +# Unity3D Generated File On Crash Reports +sysinfo.txt + +# Builds +*.apk +*.unitypackage + +### OSX ### +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# MonoDevelop +# User Specific +*.userprefs +*.usertasks + +# Mono Project Files +*.pidb +*.resources +test-results/ + +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## Build generated +build/ +DerivedData/ + +## Various settings +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata/ + +## Other +*.moved-aside +*.xccheckout +*.xcscmblueprint + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Object files +*.o +*.ko +*.obj +*.elf + +# Precompiled Headers +*.gch +*.pch + +# Debug files +*.dSYM/ +*.su + +# Misc. detritus +.svn/ +/.tgitconfig +.vscode + +# All Visual Studio from here on down. Typical. +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +*.sln.iml + + diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..31f9c87 --- /dev/null +++ b/.jshintrc @@ -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 +} diff --git a/CHANGES b/CHANGES index 8ff7d8b..2cdb1a9 100644 --- a/CHANGES +++ b/CHANGES @@ -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 @@ -11,4 +16,4 @@ v0.0.2 (19 Jul 2013) Bump version. v0.0.1 (01 Apr 2013) - First release. \ No newline at end of file + First release. diff --git a/LICENSE b/LICENSE index 81203c4..6a4f037 100644 --- a/LICENSE +++ b/LICENSE @@ -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 @@ -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. \ No newline at end of file +THE SOFTWARE. diff --git a/README.md b/README.md index dd222b6..4c0779c 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,24 @@ streamifier [![npm][npm-image]][npm-url] - -___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 \ No newline at end of file +[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 diff --git a/examples/buffer-stream.js b/examples/buffer-stream.js index b84adbc..d432992 100644 --- a/examples/buffer-stream.js +++ b/examples/buffer-stream.js @@ -1,6 +1,6 @@ 'use strict'; -var streamifier = require('../lib'); +var streamifier = require('../'); streamifier.createReadStream(new Buffer ([97, 98, 99])).pipe(process.stdout); -// abc \ No newline at end of file +// abc diff --git a/examples/object-stream.js b/examples/object-stream.js index 7f4082e..b1ff7c3 100644 --- a/examples/object-stream.js +++ b/examples/object-stream.js @@ -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 @@ -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} \ No newline at end of file +// {'a':1,'b':2} diff --git a/examples/string-stream.js b/examples/string-stream.js index 9765e02..533c2d6 100644 --- a/examples/string-stream.js +++ b/examples/string-stream.js @@ -1,6 +1,6 @@ 'use strict'; -var streamifier = require('../lib'); +var streamifier = require('../'); streamifier.createReadStream('abc').pipe(process.stdout); -// abc \ No newline at end of file +// abc diff --git a/index.js b/index.js new file mode 100644 index 0000000..3ac93d3 --- /dev/null +++ b/index.js @@ -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 ); diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6d83bd9..0000000 --- a/lib/index.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -var util = require('util'); -var stream = require('stream'); - -module.exports.createReadStream = function (object, options) { - return new MultiStream (object, options); -}; - -var MultiStream = function (object, options) { - if (object instanceof Buffer || typeof object === 'string') { - options = options || {}; - stream.Readable.call(this, { - highWaterMark: options.highWaterMark, - encoding: options.encoding - }); - } else { - stream.Readable.call(this, { objectMode: true }); - } - this._object = object; -}; - -util.inherits(MultiStream, stream.Readable); - -MultiStream.prototype._read = function () { - this.push(this._object); - this._object = null; -}; \ No newline at end of file diff --git a/package.json b/package.json index 2d1df26..16ca9d0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "streamifier", - "version": "0.1.1", + "version": "0.2.0", "description": "Converts a Buffer/String into a readable stream", "keywords": [ "string", @@ -8,11 +8,14 @@ "readable", "stream" ], - "author": "Gabriel Llamas ", + "author": [ + "Gabriel Llamas ", + "Nick Soggin " + ], "repository": "git://github.com/gagle/node-streamifier.git", "engines": { "node": ">=0.10" }, "license": "MIT", - "main": "lib" -} \ No newline at end of file + "main": "index.js" +}