read-remove-file
Version:
Read a file, then remove it
53 lines (36 loc) • 1.68 kB
Markdown
# read-remove-file
[](https://www.npmjs.com/package/read-remove-file)
[](https://travis-ci.org/shinnn/node-read-remove-file)
[](https://ci.appveyor.com/project/ShinnosukeWatanabe/node-read-remove-file)
[](https://coveralls.io/github/shinnn/node-read-remove-file?branch=master)
Read a file, then remove it
```javascript
const readRemoveFile = require('read-remove-file');
readRemoveFile('path/to/file').then(buf => {
buf; //=> <Buffer ... >
fs.accessSync('path/to/file'); // Error: ENOENT
});
```
## Installation
[Use npm.](https://docs.npmjs.com/cli/install)
```
npm install read-remove-file
```
## API
```javascript
const readRemoveFile = require('read-remove-file');
```
### readRemoveFile(*filePath* [, *options*])
*filePath*: `String`
*options*: `Object` or `String` ([`fs.readFile`][fs.readFile] options)
Return: `Promise`
It [reads a file][fs.readFile], [removes the file](https://nodejs.org/api/fs.html#fs_fs_unlink_path_callback) and returns a [promise](https://promisesaplus.com/) of the file contents.
```javascript
readRemoveFile('path/to/file', 'utf8').then(str => {
str; //=> 'file contents'
fs.accessSync('path/to/file'); // Error: ENOENT
});
```
## License
[ISC License](./LICENSE) © 2018 Shinnosuke Watanabe
[fs.readFile]: https://nodejs.org/api/fs.html#fs_fs_readfile_path_options_callback