{"id":17398425,"url":"https://github.com/vweevers/fs-lotus","last_synced_at":"2025-03-29T20:15:38.388Z","repository":{"id":55828380,"uuid":"76198232","full_name":"vweevers/fs-lotus","owner":"vweevers","description":"Sugar to open and close a file descriptor","archived":false,"fork":false,"pushed_at":"2020-12-11T17:47:46.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T21:39:05.586Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vweevers.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-11T20:31:55.000Z","updated_at":"2016-12-11T21:33:46.000Z","dependencies_parsed_at":"2022-08-15T07:31:19.242Z","dependency_job_id":null,"html_url":"https://github.com/vweevers/fs-lotus","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vweevers%2Ffs-lotus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vweevers%2Ffs-lotus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vweevers%2Ffs-lotus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vweevers%2Ffs-lotus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vweevers","download_url":"https://codeload.github.com/vweevers/fs-lotus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246237436,"owners_count":20745348,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-16T14:56:13.308Z","updated_at":"2025-03-29T20:15:38.364Z","avatar_url":"https://github.com/vweevers.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"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\u0026label=travis)](http://travis-ci.org/vweevers/fs-lotus) [![AppVeyor build status](https://img.shields.io/appveyor/ci/vweevers/fs-lotus.svg?style=flat-square\u0026label=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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvweevers%2Ffs-lotus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvweevers%2Ffs-lotus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvweevers%2Ffs-lotus/lists"}