vinyl-contents
Utility to read the contents of a vinyl file.
Last updated 2 years ago by phated .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install vinyl-contents 
SYNC missed versions from official npm registry.

vinyl-contents

NPM version Downloads Azure Pipelines Build Status Travis Build Status AppVeyor Build Status Coveralls Status Gitter chat

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 through = require('through2');
var pug = require('pug');
var vinylContents = require('vinyl-contents');

function gulpPug(options) {
  return through.obj(function(file, _enc, 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

Current Tags

  • 1.0.0                                ...           latest (2 years ago)

1 Versions

  • 1.0.0                                ...           2 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (3)
Dev Dependencies (7)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |