vinyl-readfile-promise

Promise to create a vinyl file object from an actual file

Usage no npm install needed!

<script type="module">
  import vinylReadfilePromise from 'https://cdn.skypack.dev/vinyl-readfile-promise';
</script>

README

vinyl-readfile-promise

NPM version Build Status Build status Coverage Status Dependency Status devDependency Status

Promises/A+ version of vinyl-file:

Create a vinyl file from an actual file

var vinylReadFile = require('vinyl-readfile-promise');

vinylReadFile('index.js')
.then(function(file) {
  file.path; //=> /root/dir/index.js
  file.cwd; //=> /root/dir
})
.catch(), function(err) {
  throw err;
});

Installation

Use npm.

npm install vinyl-readfile-promise

API

var vinylReadFile = require('vinyl-readfile-promise');

vinylReadFile(filePath [, options])

filePath: String
options: Object (directly passed to vinyl-file options)
Return: Object (Promise)

When it finish reading a file, it will be fulfilled with a vinyl file object as an argument.

When it fails to read a file, it will be rejected with an error as an argument.

var vinylReadFile = require('vinyl-readfile-promise');

function onFulFilled(file) {
  file.isNull(); //=> false
  file.isBuffer(); //=> false
  file.isBuffer(); //=> true
}

function onRejected(err) {
  throw err;
}

vinylReadFile('path/to/file', {buffer: false}).then(onFulFilled, onRejected);

License

Copyright (c) Shinnosuke Watanabe

Licensed under the MIT License.