vinyl-contents

2.0.0 • Public • Published

vinyl-contents

NPM version Downloads Build Status Coveralls Status

Utility to read the contents of a vinyl file.

Usage

/*
  WARNING: This is a very naive plugin implementation
  It is only meant for demonstation purposes.
  For a more complete implementation, see: https://github.com/gulp-community/gulp-pug
*/
var { Transform } = require('streamx');
var pug = require('pug');
var vinylContents = require('vinyl-contents');

function gulpPug(options) {
  return new Transform({
    transform: function (file, cb) {
      vinylContents(file, function (err, contents) {
        if (err) {
          return cb(err);
        }

        if (!contents) {
          return cb();
        }

        file.contents = pug.compile(contents.toString(), options)();
        cb(null, file);
      });
    },
  });
}

API

vinylContents(file, callback)

Warning: Only use this if interacting with a library that can only receive strings or buffers. This loads all streaming contents into memory which can cause unexpected results for your end-users.

Takes a Vinyl file and an error-first callback. Calls the callback with an error if one occur (or if the first argument is not a Vinyl file), or the file contents if no error occurs.

If the Vinyl contents are:

  • A Buffer, will be returned directly.
  • A Stream, will be buffered into a BufferList and returned.
  • Empty, will be undefined.

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i vinyl-contents

Weekly Downloads

304,199

Version

2.0.0

License

MIT

Unpacked Size

5.02 kB

Total Files

4

Last publish

Collaborators

  • yocontra
  • phated