coleccionista
Advanced tools
Comparing version 0.0.3 to 0.1.0
41
index.js
"use strict"; | ||
var inherits = require("util").inherits; | ||
var fs = require("fs"); | ||
let path = require("path"); | ||
var PassThrough = require("stream").PassThrough; | ||
var inherits = require("util").inherits; | ||
var glob = require("glob"); | ||
var isArray = Array.isArray; | ||
var Coleccionista = function(filesOrStreams, options) { | ||
if(!filesOrStreams.length) { | ||
throw new Error("Files argument required"); | ||
} | ||
var mapFiles = function (srcPath, files) { | ||
return files.map(function(filePath){ | ||
return path.join(srcPath, filePath); | ||
}); | ||
}; | ||
var Coleccionista = function(options, cb) { | ||
let self = this; | ||
PassThrough.call(this, options); | ||
this.files = filesOrStreams; | ||
this.fileIndex = 0; | ||
this.o = options; | ||
this.next(); | ||
this.o = options.stream; | ||
if(typeof options.files === "string") { | ||
glob(options.files, {cwd: options.path}, function(err, files) { | ||
if(err) { | ||
cb(err); | ||
} if(!files.length) { | ||
cb(new Error(options.path ? ("No files found in path " + options.path) : "No files found")); | ||
} else { | ||
self.files = files; | ||
cb(null, files); | ||
self.next(); | ||
} | ||
}); | ||
} else if(isArray(options.files)) { | ||
this.files = options.path ? mapFiles(options.path, options.files) : options.files; | ||
cb(null, this.files); | ||
self.next(); | ||
} else { | ||
throw new Error("Files option required"); | ||
} | ||
}; | ||
@@ -18,0 +43,0 @@ inherits(Coleccionista, PassThrough); |
{ | ||
"name": "coleccionista", | ||
"version": "0.0.3", | ||
"description": "Helper class that streams files one by one.", | ||
"keywords": ["stream", "files", "collect"], | ||
"author": "Alexey Novikov (http://2dubs.com)", | ||
"preferGlobal": true, | ||
"private": false, | ||
"engines": { | ||
"node": "~0.10.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:velocityzen/coleccionista.git" | ||
}, | ||
"main": ".index" | ||
"name": "coleccionista", | ||
"version": "0.1.0", | ||
"description": "Helper class that streams files one by one.", | ||
"keywords": [ | ||
"stream", | ||
"files", | ||
"collect" | ||
], | ||
"author": "Alexey Novikov (http://2dubs.com)", | ||
"preferGlobal": true, | ||
"private": false, | ||
"engines": { | ||
"node": "^0.10.0", | ||
"iojs": "^1.0.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:velocityzen/coleccionista.git" | ||
}, | ||
"main": ".index", | ||
"dependencies": { | ||
"glob": "^5.0.3" | ||
} | ||
} |
# Coleccionista # | ||
Helper stream class that streams files or other streams one by one in one stream. | ||
Streams files or other streams one by one in one stream. | ||
### Usage ### | ||
```js | ||
var Coleccionista = require('coleccionista'); | ||
let Coleccionista = require('coleccionista'); | ||
var stream = new Coleccionista(filesOrStreams, options); | ||
//filesOrStreams — array of pathes to files or array of streams | ||
//options — options for file streams | ||
let stream = new Coleccionista(options, function(err, files) { | ||
//err — if no files found or some other fs error | ||
//files — array of full file pathes | ||
}); | ||
@@ -18,5 +19,10 @@ // now we can use it like usual stream | ||
### options | ||
* **files** — array of files or wildcard string. For more info look [minimatch documentation](https://github.com/isaacs/minimatch) | ||
* **path** — optional, path to look for a files | ||
* **stream** — optional, read files stream options | ||
### Additional events ### | ||
* __itemstart__ — triggers when new file open | ||
* __itemend__ — triggers when file stream end | ||
* __itemstart__ — triggers when new file begins | ||
* __itemend__ — triggers when file stream ended | ||
* __error__ — triggers on file errors |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3998
5
59
28
1
+ Addedglob@^5.0.3
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedglob@5.0.15(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedwrappy@1.0.2(transitive)