Convert streaming vinyl files to use buffers
npx @tessl/cli install tessl/npm-vinyl-buffer@1.0.0Vinyl Buffer converts streaming vinyl files to use buffers instead of streams. It's designed for use in build systems like Gulp, providing a simple transform stream that converts file contents from streams to buffers while maintaining the vinyl file format.
npm install vinyl-bufferconst vinylBuffer = require('vinyl-buffer');Note: This package uses CommonJS exports only. For ES modules, use dynamic import:
const vinylBuffer = (await import('vinyl-buffer')).default;const browserify = require('browserify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const gulp = require('gulp');
gulp.task('build', function() {
const bundler = browserify('./index.js');
return bundler.bundle()
.pipe(source('index.js'))
.pipe(buffer()) // Convert stream to buffer
.pipe(gulp.dest('dist/'));
});Creates a transform stream that converts streaming vinyl files to use buffers, allowing compatibility with plugins that require buffer-based input.
/**
* Creates a transform stream that converts streaming vinyl files to use buffers
* @returns {NodeJS.Transform} Through2 object stream that processes vinyl files
*/
function vinylBuffer(): NodeJS.Transform;File Processing Behavior:
file.isNull()) - Passed through unchangedfile.isBuffer()) - Passed through unchangedfile.isStream()) - Contents converted to Buffer using 'bl' moduleUsage Example:
const vinylBuffer = require('vinyl-buffer');
const through = require('through2');
// Create the transform stream
const bufferTransform = vinylBuffer();
// Use in a stream pipeline
someVinylStream
.pipe(bufferTransform)
.pipe(through.obj(function(file, enc, callback) {
// file.contents is now a Buffer instead of a Stream
console.log('File is buffer:', file.isBuffer()); // true
console.log('File is stream:', file.isStream()); // false
callback(null, file);
}));Error Handling:
The transform stream will emit errors if the buffer conversion process fails, typically due to issues reading from the source stream.
This package works with vinyl file objects:
// Vinyl file interface (from vinyl package)
interface VinylFile {
isNull(): boolean;
isBuffer(): boolean;
isStream(): boolean;
contents: Buffer | NodeJS.ReadableStream | null;
}