Socket
Socket
Sign inDemoInstall

read-vinyl-file-stream

Package Overview
Dependencies
4
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.1.0

17

index.js

@@ -11,2 +11,6 @@ /* jshint node: true */

function noopFlush(stream, cb) {
cb();
}
function castData(data, enc) {

@@ -22,3 +26,12 @@ var isBuffer = Buffer.isBuffer(data);

module.exports = function iterateStream(iterator, enc) {
module.exports = function iterateStream(iterator, flush, enc) {
if (typeof flush === 'string') {
enc = flush;
flush = noopFlush;
}
if (typeof flush !== 'function') {
flush = noopFlush;
}
var stream = through.obj(function (file, fileEnc, cb) {

@@ -64,2 +77,4 @@

}
}, function (cb) {
flush(stream, cb);
});

@@ -66,0 +81,0 @@

2

package.json
{
"name": "read-vinyl-file-stream",
"version": "1.0.0",
"version": "1.1.0",
"main": "index.js",

@@ -5,0 +5,0 @@ "scripts": {

@@ -36,5 +36,8 @@ # read vinyl file stream

### read-vinyl-file-stream(iterator {Function} [, flush {Function}] [, encoding {String}])
The module is a function that creates a transform stream. It will read the vinyl file, whether it is a buffer or a stream internally. It takes the following parameters, in order:
- **iterator** _{Function}_ Required - the function that will process the files.
- **iterator** _{Function}_ Required - the method that will process the files.
- **flush** _{Function}_ Optional - the method to call before the stream ends.
- **encoding** _{String}_ Optional - the encoding to use for the content provided to the iterator function. By default, this is a UTF-8 string. The following options are supported:

@@ -44,2 +47,4 @@ - `'utf8'` - provide the content in a UTF-8 string.

### iterator(content, file, stream, cb)
The function that you provide to it has the following parameters, in order:

@@ -50,4 +55,11 @@

- **stream** - the transform stream that is being iterated.
- **cb** - a callback to call once you are done processing the file.
- **cb** - a callback to call once you are done processing the file. You must call this in order for the stream to continue.
### flush(stream, cb)
This is a function that will allow you to execute some code after all the files have been read but before the stream ends. It has the following parameters, in order:
- **stream** - the transform stream that is being iterated.
- **cb** - a callback to call once you are done with the flush actions. You must call this in order for the stream to end.
## Examples

@@ -54,0 +66,0 @@

@@ -297,2 +297,66 @@ /* jshint node: true, mocha: true */

});
it('has an optional flush method', function (done) {
var input = through.obj();
var isAsync = false;
var flushCalled = false;
var output = input.pipe(readFiles(function (content, file, stream, cb) {
cb();
}, function (stream, cb) {
expect(stream).to.have.property('pipe').and.to.be.a('function');
flushCalled = true;
setImmediate(cb);
}));
ns.wait.obj(output, function (err, data) {
expect(err).to.equal(null);
expect(isAsync).to.equal(true);
expect(flushCalled).to.equal(true);
done();
});
input.push(fileBuffer());
input.end();
isAsync = true;
});
it('can use the encoding parameter with the flush method', function (done) {
var input = through.obj();
var isAsync = false;
var flushCalled = false;
var output = input.pipe(readFiles(function (content, file, stream, cb) {
expect(Buffer.isBuffer(content)).to.equal(true);
cb();
}, function (stream, cb) {
expect(stream).to.have.property('pipe').and.to.be.a('function');
flushCalled = true;
setImmediate(cb);
}, 'buffer'));
ns.wait.obj(output, function (err, data) {
expect(err).to.equal(null);
expect(isAsync).to.equal(true);
expect(flushCalled).to.equal(true);
done();
});
input.push(fileBuffer());
input.end();
isAsync = true;
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc