updated sys and created publi
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 - 2015 Shinnosuke Watanabe
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
# fs-readfile-promise
|
||||
|
||||
[](https://www.npmjs.com/package/fs-readfile-promise)
|
||||
[](https://travis-ci.org/shinnn/fs-readfile-promise)
|
||||
[](https://ci.appveyor.com/project/ShinnosukeWatanabe/fs-readfile-promise)
|
||||
[](https://coveralls.io/r/shinnn/fs-readfile-promise)
|
||||
[](https://david-dm.org/shinnn/fs-readfile-promise)
|
||||
[](https://david-dm.org/shinnn/fs-readfile-promise#info=devDependencies)
|
||||
|
||||
[Promises/A+][promise] version of [`fs.readFile`][fs.readfile]
|
||||
|
||||
```javascript
|
||||
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*](https://en.wikipedia.org/wiki/Modular_programming), this module has only one functionality [`readFile`][fs.readfile], unlike other promise-based file system modules. If you want to use a bunch of other [`fs`](http://nodejs.org/api/fs.html) methods in the promises' way, choose other modules such as [q-io](https://github.com/kriskowal/q-io) and [fs-promise](https://github.com/kevinbeaty/fs-promise).
|
||||
|
||||
## Installation
|
||||
|
||||
[Use npm.](https://docs.npmjs.com/cli/install)
|
||||
|
||||
```
|
||||
npm install fs-readfile-promise
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
```javascript
|
||||
const readFile = require('fs-readfile-promise');
|
||||
```
|
||||
|
||||
### readFile(*filename* [, *options*])
|
||||
|
||||
*filename*: `String`
|
||||
*options*: `Object` or `String` ([fs.readFile] options)
|
||||
Return: `Object` ([Promise][promise])
|
||||
|
||||
When it finish reading the file, it will be [*fulfilled*](https://promisesaplus.com/#point-26) with an [`Buffer`](https://nodejs.org/api/buffer.html#buffer_buffer) of the file as its first argument.
|
||||
|
||||
When it fails to read the file, it will be [*rejected*](https://promisesaplus.com/#point-30) with an error as its first argument.
|
||||
|
||||
```javascript
|
||||
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](https://github.com/shinnn)
|
||||
|
||||
Licensed under [the MIT License](./LICENSE).
|
||||
|
||||
[fs.readfile]: https://nodejs.org/api/fs.html#fs_fs_readfile_filename_options_callback
|
||||
[promise]: https://promisesaplus.com/
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('graceful-fs');
|
||||
|
||||
module.exports = function fsReadFilePromise(filePath, options) {
|
||||
var resolve;
|
||||
var reject;
|
||||
|
||||
fs.readFile(filePath, options, function(err, buf) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
resolve(buf);
|
||||
});
|
||||
|
||||
return new Promise(function(_resolve, _reject) {
|
||||
resolve = _resolve;
|
||||
reject = _reject;
|
||||
});
|
||||
};
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"raw": "fs-readfile-promise@^2.0.1",
|
||||
"scope": null,
|
||||
"escapedName": "fs-readfile-promise",
|
||||
"name": "fs-readfile-promise",
|
||||
"rawSpec": "^2.0.1",
|
||||
"spec": ">=2.0.1 <3.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"/mnt/Data/bach/Documents/ola/OLA#3DOC/sys/node_modules/gulp-wrap"
|
||||
]
|
||||
],
|
||||
"_from": "fs-readfile-promise@>=2.0.1 <3.0.0",
|
||||
"_id": "fs-readfile-promise@2.0.1",
|
||||
"_inCache": true,
|
||||
"_location": "/fs-readfile-promise",
|
||||
"_nodeVersion": "2.3.3",
|
||||
"_npmUser": {
|
||||
"name": "shinnn",
|
||||
"email": "snnskwtnb@gmail.com"
|
||||
},
|
||||
"_npmVersion": "2.12.1",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"raw": "fs-readfile-promise@^2.0.1",
|
||||
"scope": null,
|
||||
"escapedName": "fs-readfile-promise",
|
||||
"name": "fs-readfile-promise",
|
||||
"rawSpec": "^2.0.1",
|
||||
"spec": ">=2.0.1 <3.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/gulp-wrap"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/fs-readfile-promise/-/fs-readfile-promise-2.0.1.tgz",
|
||||
"_shasum": "80023823981f9ffffe01609e8be668f69ae49e70",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "fs-readfile-promise@^2.0.1",
|
||||
"_where": "/mnt/Data/bach/Documents/ola/OLA#3DOC/sys/node_modules/gulp-wrap",
|
||||
"author": {
|
||||
"name": "Shinnosuke Watanabe",
|
||||
"url": "https://github.com/shinnn"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/shinnn/fs-readfile-promise/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"graceful-fs": "^4.1.2"
|
||||
},
|
||||
"description": "Promise version of fs.readFile",
|
||||
"devDependencies": {
|
||||
"@shinnn/eslintrc-node": "^1.0.2",
|
||||
"eslint": "^0.24.0",
|
||||
"istanbul": "^0.3.17",
|
||||
"istanbul-coveralls": "^1.0.3",
|
||||
"tape": "^4.0.0"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "80023823981f9ffffe01609e8be668f69ae49e70",
|
||||
"tarball": "https://registry.npmjs.org/fs-readfile-promise/-/fs-readfile-promise-2.0.1.tgz"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"gitHead": "4036c226774f54833a96a4a9a1c5a82a3a8e8e3f",
|
||||
"homepage": "https://github.com/shinnn/fs-readfile-promise#readme",
|
||||
"keywords": [
|
||||
"fs",
|
||||
"read",
|
||||
"file",
|
||||
"promise",
|
||||
"promises",
|
||||
"then",
|
||||
"thenable"
|
||||
],
|
||||
"license": "MIT",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "shinnn",
|
||||
"email": "snnskwtnb@gmail.com"
|
||||
}
|
||||
],
|
||||
"name": "fs-readfile-promise",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/shinnn/fs-readfile-promise.git"
|
||||
},
|
||||
"scripts": {
|
||||
"coverage": "node --harmony_arrow_functions node_modules/.bin/istanbul cover test.js",
|
||||
"coveralls": "${npm_package_scripts_coverage} && istanbul-coveralls",
|
||||
"pretest": "eslint --config node_modules/@shinnn/eslintrc-node/rc.json index.js test.js",
|
||||
"test": "node --harmony_arrow_functions test.js"
|
||||
},
|
||||
"version": "2.0.1"
|
||||
}
|
||||
Reference in New Issue
Block a user