Package Exports
- platform-name
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (platform-name) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
read-utf8-file
A Node module to read the contents of a UTF-8 file
const readUtf8File = require('read-utf8-file');
readUtf8File('/path/to/utf8-file.txt').then(contents => {
contents; //=> 'string of file contents'
});
Installation
npm install read-utf8-file
API
const readUtf8File = require('read-utf8-file');
readUtf8File(filePath [, options])
filePath: String
(file path)
options: Object
(fs.readFile
options except for encoding
)
Return: Promise
of String
(entire file contents except for BOM)
// file-with-bom.txt: '\uFEFFabc'
readUtf8File('file-with-bom.txt').then(contents => {
contents; //=> 'abc'
});
Note that 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 your application doesn't accept non-UTF-8 files.
readUtf8File('/path/to/non-utf8-file.exe').catch(err => {
err.message; //=> "Error: Expected a UTF-8 file, but the file at '/path/to/non-utf8-file.exe' is not UTF-8 encoded."
});
License
Copyright (c) 2016 - 2017 Shinnosuke Watanabe
Licensed under the MIT License.