with-open-file

Do stuff with an open file, knowing it will finally be closed

MIT 8 个版本
安装
npm install with-open-file
yarn add with-open-file
pnpm add with-open-file
bun add with-open-file
README

with-open-file Build Status

Do stuff with an open file, knowing it will finally be closed

Because the built-in way requires way too much boilerplate.

Install

$ npm install with-open-file

Usage

const withOpenFile = require('with-open-file')

withOpenFile('foo.txt', 'r', fd => {
  // Process file using fd
})

withOpenFile.sync('foo.txt', 'r', fd => {
  // Process file synchronously using fd
})

API

withOpenFile(...openArgs, callback)

Returns a Promise wrapping the result of calling callback with the requested file descriptor.

withOpenFile.sync(...openArgs, callback)

Returns the result of calling callback with the requested file descriptor.

...openArgs

Arguments as supported by fs.openSync

callback

Type: function

License

MIT © Raphael von der Grün

版本列表
0.1.7 2019-11-07
0.1.6 2019-03-28
0.1.5 2019-01-22
0.1.4 2018-09-12
0.1.3 2018-08-22
0.1.2 2018-08-22
0.1.1 2018-08-22
0.1.0 2018-08-22