3.0.0 • Published 5 years ago

read-utf8-file v3.0.0

Weekly downloads
7
License
ISC
Repository
github
Last release
5 years ago

read-utf8-file

npm version Build Status codecov

A Node.js module to read the contents of a UTF-8 file

const readUtf8File = require('read-utf8-file');

(async () => {
  const contents = await readUtf8File('/path/to/utf8-file.txt');
  //=> 'string of file contents'
})();

Installation

Use npm.

npm install read-utf8-file

API

const readUtf8File = require('read-utf8-file');

readUtf8File(filePath , options)

filePath: string | Buffer | Uint8Array | URL (file path)
options: Object (fs.promises.readFile() options except for encoding)
Return: Promise<string> (entire file contents except for BOM)

// file-with-bom.txt: '\uFEFFabc'

(async () => {
  await readUtf8File('file-with-bom.txt'); //=> 'abc'
})();

If the file is not UTF-8 encoded, the Promise will be rejected. So this module is more suitable than built-in fs.readFile() for the case when the program doesn't support non-UTF-8 files.

(async () => {
  await readUtf8File('/path/to/non-utf8-file');
  // rejects with Error: Expected a UTF-8 file, but the file at '/path/to/non-utf8-file' is not UTF-8 encoded.
})();

License

ISC License © 2017 - 2019 Watanabe Shinnosuke

3.0.0

5 years ago

3.0.0-0

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

6 years ago

2.0.0-0

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.4.0

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.0

7 years ago