Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gulpjs/vinyl-contents
Utility to read the contents of a vinyl file.
https://github.com/gulpjs/vinyl-contents
gulp gulp-plugins gulpplugin javascript nodejs streams vinyl
Last synced: 5 days ago
JSON representation
Utility to read the contents of a vinyl file.
- Host: GitHub
- URL: https://github.com/gulpjs/vinyl-contents
- Owner: gulpjs
- License: mit
- Created: 2019-05-11T15:01:26.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-02-28T02:53:34.000Z (almost 2 years ago)
- Last Synced: 2024-10-29T15:14:39.509Z (3 months ago)
- Topics: gulp, gulp-plugins, gulpplugin, javascript, nodejs, streams, vinyl
- Language: JavaScript
- Size: 16.6 KB
- Stars: 3
- Watchers: 6
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# vinyl-contents
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url]
Utility to read the contents of a vinyl file.
## Usage
```js
/*
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
[downloads-image]: https://img.shields.io/npm/dm/vinyl-contents.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/vinyl-contents
[npm-image]: https://img.shields.io/npm/v/vinyl-contents.svg?style=flat-square[ci-url]: https://github.com/gulpjs/vinyl-contents/actions?query=workflow:dev
[ci-image]: https://img.shields.io/github/actions/workflow/status/gulpjs/vinyl-contents/dev.yml?branch=master&style=flat-square[coveralls-url]: https://coveralls.io/r/gulpjs/vinyl-contents
[coveralls-image]: https://img.shields.io/coveralls/gulpjs/vinyl-contents/master.svg?style=flat-square