Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
vinyl-bufferstream
Advanced tools
Deal with vinyl file contents, regardless of whether it is Buffer/Stream
Deal with vinyl file contents, regardless of whether it is Buffer/Stream
var through = require('through2');
var VinylBufferStream = require('vinyl-bufferstream');
function yourGulpPlugin() {
var vinylBufferStream = new VinylBufferStream(function(buf, done) {
syncOrAsyncFn(buf, done);
});
return through.obj(function(file, enc, cb) {
vinylBufferStream(file, function(err, contents) {
if (err) {
self.emit('error', err);
} else {
file.contents = contents;
self.push(file);
}
cb();
});
});
}
npm install vinyl-bufferstream
var VinylBufferStream = require('vinyl-bufferstream');
(new
operator is optional.)
transformFunction: Function
Return: Function
The argument must be a function taking a Buffer
and a callback function as its first and second argument, which calls the callback function with passing Node-style callback arguments (error, result
).
file: Object
(vinyl file object)
callback: Function
When the file.contents
is a Buffer
, it will call the transformFunction with passing file.contents to the first argument.
When the file.contents
is a Stream
, it will call the transformFunction with passing the buffered stream of file.contents to the first argument.
When the file.contents
is a Stream
, it won't call the transformFunction.
error: Error
or null
contents: Buffer
or Stream
When the file.contents
is a Buffer
, contents will be a result that transformFunction produces.
When the file.contents
is a Stream
, contents will be a stream that emits a data transformFunction produces.
When the file.contents
is null
, contents will be null
.
var gulp = require('gulp');
var SVGO = require('svgo');
var through = require('through2');
var VinylBufferStream = require('vinyl-bufferstream');
function svgminPlugin(options) {
var svgo = new SVGO(options);
var vinylBufferStream = new VinylBufferStream(function(buf, done) {
svgo.optimize(String(buf), function(result) {
if (result.error) {
done(result.error);
return;
}
done(null, result.data);
});
});
return through.obj(function(file, enc, cb) {
vinylBufferStream(file, function(err, contents) {
if (err) {
self.emit('error', err);
} else {
file.contents = contents;
self.push(file);
}
cb();
});
});
}
gulp.task('buffer', function() {
return gulp.src('*.svg')
.pipe(svgminPlugin())
.pipe(gulp.dest('dest'));
});
gulp.task('stream', function() {
return gulp.src('*.svg', {buffer: false})
.pipe(svgminPlugin())
.pipe(gulp.dest('dest'));
});
Copyright (c) 2014 - 2015 Shinnosuke Watanabe
Licensed under the MIT License.
FAQs
Deal with vinyl file contents, regardless of whether it is Buffer/Stream
The npm package vinyl-bufferstream receives a total of 43,760 weekly downloads. As such, vinyl-bufferstream popularity was classified as popular.
We found that vinyl-bufferstream demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.