{"_id":"fs-maybe-open","_rev":"3-214b3deb4d3cb9de4c41e7728df561a6","name":"fs-maybe-open","description":"Open a file unless already an fd","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"fs-maybe-open","version":"1.0.0","description":"Open a file unless already an fd","license":"MIT","author":{"name":"Vincent Weevers"},"files":["index.js"],"scripts":{"test":"node test.js"},"dependencies":{"fs-lotus":"~1.0.1"},"devDependencies":{"tape":"~4.6.3"},"repository":{"type":"git","url":"git+https://github.com/vweevers/fs-maybe-open.git"},"bugs":{"url":"https://github.com/vweevers/fs-maybe-open/issues"},"homepage":"https://github.com/vweevers/fs-maybe-open","keywords":["fd","fs","open"],"engines":{"node":">=4.0.0","npm":">=2.0.0"},"gitHead":"1fc1c3b6b728a7f95c002fad5f5eb4bbb42a8b3b","_id":"fs-maybe-open@1.0.0","_shasum":"2a4f182510baf294ea6c246460ec835b47f4330d","_from":".","_npmVersion":"4.0.3","_nodeVersion":"6.8.0","_npmUser":{"name":"vweevers","email":"dev@vincentweevers.nl"},"maintainers":[{"name":"vweevers","email":"dev@vincentweevers.nl"}],"dist":{"shasum":"2a4f182510baf294ea6c246460ec835b47f4330d","tarball":"https://registry.npmjs.org/fs-maybe-open/-/fs-maybe-open-1.0.0.tgz","integrity":"sha512-rNV3i45CvtPZUQYXsTCBTVebe4h8S3VRtmTq/NIXXQsWb/8v0e5QU7hxiC98ZtvQ6iKxFeeNjLhjzbzmW6oOUg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBwXKye1VpI0K2yPHDQRRkJjKsni9yN9jIHbLe05Ezu+AiAW38REOAEQNk7ewY2038Kg0wx6AMJ5fOFd7L01qMpw9g=="}]},"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/fs-maybe-open-1.0.0.tgz_1482057917288_0.015372090507298708"}}},"readme":"# fs-maybe-open\n\n**Open a file unless it's already a file descriptor.**\n\n[![npm status](http://img.shields.io/npm/v/fs-maybe-open.svg?style=flat-square)](https://www.npmjs.org/package/fs-maybe-open) [![node](https://img.shields.io/node/v/fs-maybe-open.svg?style=flat-square)](https://www.npmjs.org/package/fs-maybe-open) [![Travis build status](https://img.shields.io/travis/vweevers/fs-maybe-open.svg?style=flat-square&label=travis)](http://travis-ci.org/vweevers/fs-maybe-open) [![AppVeyor build status](https://img.shields.io/appveyor/ci/vweevers/fs-maybe-open.svg?style=flat-square&label=appveyor)](https://ci.appveyor.com/project/vweevers/fs-maybe-open) [![Dependency status](https://img.shields.io/david/vweevers/fs-maybe-open.svg?style=flat-square)](https://david-dm.org/vweevers/fs-maybe-open)\n\n## usage\n\n```js\nconst maybeOpen = require('fs-maybe-open')\n    , fs = require('fs')\n\nfunction readExactly(fdOrFile, pos, length, done) {\n  maybeOpen(fdOrFile, 'r', function (err, fd, maybeClose) {\n    if (err) return done(err)\n\n    fs.read(fd, Buffer(length), 0, length, pos, function (err, bytesRead, buf) {\n      if (err) return maybeClose(done, err)\n\n      if (bytesRead !== length) {\n        return maybeClose(done, new Error('End of file'))\n      }\n\n      maybeClose(done, null, buf)\n    })\n  })\n}\n```\n\nThe `maybeOpen` function has the same signature as [`fs.open(path, flags[, mode], callback)`](https://nodejs.org/api/fs.html#fs_fs_open_path_flags_mode_callback). Except:\n\n- If `path` is a file descriptor, opening is a noop\n- The open `callback` also receives a `maybeClose(callback, err, ...args)` function, which calls `fs.close` for you if `path` was a filename. An error from `fs.close` (if any) will be [combined](https://github.com/matthewmueller/combine-errors) with your error (if any).\n\n## install\n\nWith [npm](https://npmjs.org) do:\n\n```\nnpm install fs-maybe-open\n```\n\n## license\n\n[MIT](http://opensource.org/licenses/MIT) © Vincent Weevers\n","maintainers":[{"name":"vweevers","email":"dev@vincentweevers.nl"}],"time":{"modified":"2022-06-18T03:53:58.840Z","created":"2016-12-18T10:45:17.867Z","1.0.0":"2016-12-18T10:45:17.867Z"},"homepage":"https://github.com/vweevers/fs-maybe-open","keywords":["fd","fs","open"],"repository":{"type":"git","url":"git+https://github.com/vweevers/fs-maybe-open.git"},"author":{"name":"Vincent Weevers"},"bugs":{"url":"https://github.com/vweevers/fs-maybe-open/issues"},"license":"MIT","readmeFilename":"readme.md"}