{"_id":"fs-lotus","_rev":"437801","name":"fs-lotus","description":"Sugar to open and close a file descriptor","dist-tags":{"latest":"1.0.1"},"maintainers":[{"name":"vweevers","email":""}],"time":{"modified":"2021-08-05T06:23:01.000Z","created":"2016-12-11T22:06:53.985Z","1.0.1":"2016-12-11T22:06:53.985Z"},"users":{},"author":{"name":"Vincent Weevers"},"repository":{"type":"git","url":"git+https://github.com/vweevers/fs-lotus.git"},"versions":{"1.0.1":{"name":"fs-lotus","version":"1.0.1","description":"Sugar to open and close a file descriptor","license":"MIT","author":{"name":"Vincent Weevers"},"scripts":{"test":"node test.js"},"files":["index.js"],"dependencies":{"combine-errors":"~3.0.3"},"devDependencies":{"tape":"~4.6.3"},"repository":{"type":"git","url":"git+https://github.com/vweevers/fs-lotus.git"},"bugs":{"url":"https://github.com/vweevers/fs-lotus/issues"},"homepage":"https://github.com/vweevers/fs-lotus","keywords":["close","fd","fs","open"],"engines":{"node":">=4.0.0","npm":">=2.0.0"},"gitHead":"8cffb726c526cd512e8459a5d054c4b57b04af23","_id":"fs-lotus@1.0.1","_shasum":"93c567ff83f2a0a310eb0ebab116bb965e774ac8","_from":".","_npmVersion":"3.10.8","_nodeVersion":"6.8.0","_npmUser":{"name":"vweevers","email":"dev@vincentweevers.nl"},"maintainers":[{"name":"vweevers","email":""}],"dist":{"shasum":"93c567ff83f2a0a310eb0ebab116bb965e774ac8","size":2156,"noattachment":false,"key":"/fs-lotus/-/fs-lotus-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/fs-lotus/download/fs-lotus-1.0.1.tgz"},"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/fs-lotus-1.0.1.tgz_1481494013381_0.5741061305161566"},"directories":{},"publish_time":1481494013985,"_cnpm_publish_time":1481494013985,"_hasShrinkwrap":false}},"readme":"# fs-lotus\n\n**Sugar to open and close a file descriptor.**\n\n[![npm status](http://img.shields.io/npm/v/fs-lotus.svg?style=flat-square)](https://www.npmjs.org/package/fs-lotus) [![node](https://img.shields.io/node/v/fs-lotus.svg?style=flat-square)](https://www.npmjs.org/package/fs-lotus) [![Travis build status](https://img.shields.io/travis/vweevers/fs-lotus.svg?style=flat-square&label=travis)](http://travis-ci.org/vweevers/fs-lotus) [![AppVeyor build status](https://img.shields.io/appveyor/ci/vweevers/fs-lotus.svg?style=flat-square&label=appveyor)](https://ci.appveyor.com/project/vweevers/fs-lotus) [![Dependency status](https://img.shields.io/david/vweevers/fs-lotus.svg?style=flat-square)](https://david-dm.org/vweevers/fs-lotus)\n\n## usage\n\n```js\nconst open = require('fs-lotus')\n    , fs = require('fs')\n\nconst readExactly = function (filename, pos, length, done) {\n  open(filename, 'r', function (err, fd, close) {\n    if (err) return done(err)\n\n    fs.read(fd, Buffer(length), 0, length, pos, function (err, bytesRead, buf) {\n      if (err) return close(done, err)\n\n      if (bytesRead !== length) {\n        return close(done, new Error('End of file'))\n      }\n\n      close(done, null, buf)\n    })\n  })\n}\n```\n\nThe `open` 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 that `callback` also receives a `close(callback, err, ...args)` function, which calls `fs.close` for you. An error from `fs.close` (if any) will be [combined](https://github.com/matthewmueller/combine-errors) with your error (if any).\n\nThis pattern ensures that our `readExactly` function doesn't leak fd's.\n\n```js\nreadExactly('readme.md', 0, 10, function (err, buf) {\n  console.log(buf.toString()) // '# fs-lotus'\n})\n\nreadExactly('readme.md', 1e5, 10, function (err, buf) {\n  console.log(err.toString()) // 'Error: End of file'\n})\n```\n\n## install\n\nWith [npm](https://npmjs.org) do:\n\n```\nnpm install fs-lotus\n```\n\n## license\n\n[MIT](http://opensource.org/licenses/MIT) © Vincent Weevers\n","_attachments":{},"homepage":"https://github.com/vweevers/fs-lotus","bugs":{"url":"https://github.com/vweevers/fs-lotus/issues"},"license":"MIT"}