CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-vinyl-buffer

Convert streaming vinyl files to use buffers

Pending
Overview
Eval results
Files

Vinyl Buffer

Vinyl 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.

Package Information

  • Package Name: vinyl-buffer
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install vinyl-buffer

Core Imports

const vinylBuffer = require('vinyl-buffer');

Note: This package uses CommonJS exports only. For ES modules, use dynamic import:

const vinylBuffer = (await import('vinyl-buffer')).default;

Basic Usage

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/'));
});

Capabilities

Stream to Buffer Conversion

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:

  • Null files (file.isNull()) - Passed through unchanged
  • Buffer files (file.isBuffer()) - Passed through unchanged
  • Stream files (file.isStream()) - Contents converted to Buffer using 'bl' module

Usage 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.

Types

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;
}

Install with Tessl CLI

npx tessl i tessl/npm-vinyl-buffer
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/vinyl-buffer@1.0.x