fs-readfile-promise

Promise version of fs.readFile

ISC 12 个版本
安装
npm install fs-readfile-promise
yarn add fs-readfile-promise
pnpm add fs-readfile-promise
bun add fs-readfile-promise
README

fs-readfile-promise

npm version Build Status Build status Coverage Status

Promisified version of fs.readFile

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

(async () => {
  const buffer = await readFile('path/to/a/file');
  buffer.toString(); //=> '... file contents ...'
})();

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

Installation

Use npm.

npm install fs-readfile-promise

API

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

readFile(path [, options])

path: string Buffer URL integer
options: Object (fs.readFile options) or string (encoding)
Return: Promise<Buffer|string>

(async () => {
  await readFilePromise('src.txt'); //=> <Buffer 48 69 2e>
  await readFilePromise('src.txt', 'utf8'); //=> 'Hi.'
  await readFilePromise('src.txt', {encoding: 'base64'}); //=> 'SGku'
})();

License

ISC License © 2017 Shinnosuke Watanabe

版本列表
4.0.0-2 2017-12-27
4.0.0-1 2017-12-26
4.0.0-0 2017-12-26
3.0.1 2017-12-26
3.0.0 2016-05-25
2.0.1 2015-07-07
2.0.0 2015-05-30
1.1.0 2014-12-07
1.0.1 2014-10-19
1.0.0 2014-09-07
0.1.0 2014-08-07
0.0.0 2014-08-06