{"_id":"fs-maybe-open","_rev":"437796","name":"fs-maybe-open","description":"Open a file unless already an fd","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"vweevers","email":""}],"time":{"modified":"2021-08-05T06:22:57.000Z","created":"2016-12-18T10:45:17.867Z","1.0.0":"2016-12-18T10:45:17.867Z"},"users":{},"author":{"name":"Vincent Weevers"},"repository":{"type":"git","url":"git+https://github.com/vweevers/fs-maybe-open.git"},"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":""}],"dist":{"shasum":"2a4f182510baf294ea6c246460ec835b47f4330d","size":2084,"noattachment":false,"key":"/fs-maybe-open/-/fs-maybe-open-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/fs-maybe-open/download/fs-maybe-open-1.0.0.tgz"},"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/fs-maybe-open-1.0.0.tgz_1482057917288_0.015372090507298708"},"directories":{},"publish_time":1482057917867,"_cnpm_publish_time":1482057917867,"_hasShrinkwrap":false}},"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","_attachments":{},"homepage":"https://github.com/vweevers/fs-maybe-open","bugs":{"url":"https://github.com/vweevers/fs-maybe-open/issues"},"license":"MIT"}