Bachir Soussi Chiadmi cefd1c2ad0 updated sys and created publi 7 år sedan
..
LICENSE cefd1c2ad0 updated sys and created publi 7 år sedan
README.md cefd1c2ad0 updated sys and created publi 7 år sedan
index.js cefd1c2ad0 updated sys and created publi 7 år sedan
package.json cefd1c2ad0 updated sys and created publi 7 år sedan

README.md

fs-readfile-promise

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

Promises/A+ version of fs.readFile

var readFile = require('fs-readfile-promise');

readFile('path/to/file')
.then(buffer => console.log(buffer.toString()))
.catch(err => console.log(err.message));

Based on the principle of modular programming, this module has only one functionality readFile, unlike other promise-based file system modules. If you want to use a bunch of other fs methods in the promises' way, choose other modules such as q-io and fs-promise.

Installation

Use npm.

npm install fs-readfile-promise

API

const readFile = require('fs-readfile-promise');

readFile(filename [, options])

filename: String
options: Object or String (fs.readFile options)
Return: Object (Promise)

When it finish reading the file, it will be fulfilled with an Buffer of the file as its first argument.

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

const readFile = require('fs-readfile-promise');

const onFulfilled = buffer => console.log(buffer.toString());
const onRejected = err => console.log('Cannot read the file.');

readFile('path/to/file').then(onFulfilled, onRejected);

License

Copyright (c) 2014 - 2015 Shinnosuke Watanabe

Licensed under the MIT License.