Skip to content

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

License

Notifications You must be signed in to change notification settings

raphinesse/with-open-file

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published