{"_id":"@apr144/generic-filehandle","name":"@apr144/generic-filehandle","dist-tags":{"latest":"3.1.1-020925-001"},"versions":{"3.1.1-020925-001":{"name":"@apr144/generic-filehandle","description":"uniform interface for accessing binary data from local files, remote HTTP resources, and browser Blob data","version":"3.1.1-020925-001","main":"dist/index.js","module":"esm/index.js","repository":{"type":"git","url":"git+https://github.com/alexpreynolds/generic-filehandle.git"},"license":"MIT","author":{"name":"Colin Diesh","email":"colin.diesh@gmail.com","url":"https://github.com/cmdcolin"},"engines":{"node":">=12"},"scripts":{"test":"jest","coverage":"npm test -- --coverage","lint":"eslint --ext .ts src test","clean":"rimraf dist esm","prebuild":"npm run clean","build:esm":"tsc --target es2018 --outDir esm","build:es5":"tsc --target es2015 --module commonjs --outDir dist","build":"npm run build:esm && npm run build:es5","watch":"babel src --out-dir dist --extensions \".ts,.tsx\" --source-maps inline --watch","preversion":"npm run lint && npm test && npm run build","version":"standard-changelog && git add CHANGELOG.md","postversion":"git push --follow-tags"},"keywords":["bionode","biojs","ucsc","genomics"],"dependencies":{"base-64":"^1.0.0","es6-promisify":"^6.1.1"},"devDependencies":{"@types/base-64":"^1.0.2","@types/fetch-mock":"^7.3.0","@types/jest":"^29.2.4","@types/node":"^12.12.6","@types/range-parser":"^1.2.3","@typescript-eslint/eslint-plugin":"^5.46.1","@typescript-eslint/parser":"^5.46.1","cross-fetch":"^3.0.3","eslint":"^8.30.0","eslint-config-prettier":"^8.5.0","eslint-plugin-import":"^2.10.0","eslint-plugin-prettier":"^4.2.1","fetch-mock":"^9.7.0","jest":"^29.3.1","jest-environment-jsdom":"^29.3.1","prettier":"^2.8.1","range-parser":"^1.2.1","rimraf":"^3.0.2","standard-changelog":"^2.0.24","tenacious-fetch":"^2.3.0","ts-jest":"^29.0.3","typescript":"^4.9.4"},"publishConfig":{"access":"public"},"browser":{"./dist/localFile.js":false,"./esm/localFile.js":false,"file-uri-to-path":false},"_id":"@apr144/generic-filehandle@3.1.1-020925-001","gitHead":"0d0fd24a9a7abad6a4dcfb31e843eaf681124f74","types":"./dist/index.d.ts","bugs":{"url":"https://github.com/alexpreynolds/generic-filehandle/issues"},"homepage":"https://github.com/alexpreynolds/generic-filehandle#readme","_nodeVersion":"20.9.0","_npmVersion":"10.1.0","dist":{"integrity":"sha512-J98Hp+X+NY018v/Ds2XWHxgmD4pjXZmZfHTH7snn3y7S0C1P8QQTFORPFbwxntvVCtGFrn+FE8yqzTWynzMZNg==","shasum":"f74b03bb7895f6471d191a8b79a4d45950337e32","tarball":"https://registry.npmjs.org/@apr144/generic-filehandle/-/generic-filehandle-3.1.1-020925-001.tgz","fileCount":38,"unpackedSize":84205,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDAiqd/T29UREBldqz1W9c8cFAAqakE8wj5dT5lwnadVwIhAMkCOS+rMZWQeEx16IBlGaoUmGuFaY8jlb7J1psXdCKs"}]},"_npmUser":{"name":"apr144","email":"alexpreynolds@gmail.com"},"directories":{},"maintainers":[{"name":"apr144","email":"alexpreynolds@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/generic-filehandle_3.1.1-020925-001_1739144567896_0.4756576537971706"},"_hasShrinkwrap":false}},"time":{"created":"2025-02-09T23:42:47.820Z","3.1.1-020925-001":"2025-02-09T23:42:48.108Z","modified":"2025-02-09T23:42:48.373Z"},"maintainers":[{"name":"apr144","email":"alexpreynolds@gmail.com"}],"description":"uniform interface for accessing binary data from local files, remote HTTP resources, and browser Blob data","homepage":"https://github.com/alexpreynolds/generic-filehandle#readme","keywords":["bionode","biojs","ucsc","genomics"],"repository":{"type":"git","url":"git+https://github.com/alexpreynolds/generic-filehandle.git"},"author":{"name":"Colin Diesh","email":"colin.diesh@gmail.com","url":"https://github.com/cmdcolin"},"bugs":{"url":"https://github.com/alexpreynolds/generic-filehandle/issues"},"license":"MIT","readme":"# generic-filehandle\n\n[![NPM version](https://img.shields.io/npm/v/generic-filehandle.svg?style=flat-square)](https://npmjs.org/package/generic-filehandle)\n[![Coverage Status](https://img.shields.io/codecov/c/github/GMOD/generic-filehandle/master.svg?style=flat-square)](https://codecov.io/gh/GMOD/generic-filehandle/branch/master)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/GMOD/generic-filehandle/push.yml?branch=master)](https://github.com/GMOD/generic-filehandle/actions)\n\nProvides a uniform interface for accessing binary data from local files, remote HTTP resources, and Blob data in the browser. Implements a subset of the [Node.js v10 promise-based FileHandle API](https://nodejs.org/api/fs.html#fs_class_filehandle).\n\n## Usage\n\n```js\nimport { LocalFile, RemoteFile, BlobFile } from 'generic-filehandle'\n\n// operate on a local file path\nconst local = new LocalFile('/some/file/path/file.txt')\n\n// operate on a remote file path\nconst remote = new RemoteFile('http://somesite.com/file.txt')\n\n// operate on blob objects\nconst blobfile = new BlobFile(new Blob([some_existing_buffer], { type: 'text/plain' }))\n\n// read slice of file, works on remote files with range request, pre-allocate buffer\nconst buf = Buffer.alloc(10)\nconst { bytesRead } = await remote.read(buf, 0, 10, 10)\nconsole.log(buf.toString())\n\n// readFile, returns buffer\nconst buf = remote.readFile()\n```\n\nImportant: under node.js, you should supply a fetch function to the RemoteFile constructor\n\n```js\nimport { RemoteFile } from 'generic-filehandle'\nimport fetch from 'node-fetch'\nconst remote = new RemoteFile('http://somesite.com/file.txt', { fetch })\n```\n\n## API\n\n### async read(buf:Buffer, offset: number=0, length: number, position: number=0, opts?: Options): Promise<{bytesRead:number,buffer:Buffer}>\n\n- buf - a pre-allocated buffer that can contain length bytes\n- offset - an offset into the buffer to write into\n- length - a length of data to read\n- position - the byte offset in the file to read from\n- opts - optional Options object\n\nReturns a Promise for the number of bytes read, and the data will be copied\ninto the Buffer provided in the arguments.\n\n### async readFile(opts?: Options): Promise<Buffer | string>\n\nReturns a Promise for a buffer or string containing the contents of the whole file.\n\n### async stat() : Promise<{size: number}>\n\nReturns a Promise for an object containing as much information about the file as is available. At minimum, the `size` of the file will be present.\n\n### async close() : Promise<void>\n\nCloses the filehandle.\n\n### Options\n\nThe Options object for the constructor, `read` and `readFile` can contain abort signal\nto customize behavior. All entries are optional.\n\n- signal `<AbortSignal>` - an AbortSignal that is passed to remote file fetch() API or other file readers\n- headers `<Object <string, string> >`- extra HTTP headers to pass to remote file fetch() API\n- overrides `<Object>` - extra parameters to pass to the remote file fetch() API\n- fetch `<Function>` - a custom fetch callback, otherwise defaults to the environment (initialized in constructor)\n- encoding `<string>` - if specified, then this function returns a string. Otherwise it returns a buffer. Currently only `utf8` encoding is supported.\n\nThe Options object for `readFile` can also contain an entry `encoding`. The\ndefault is no encoding, in which case the file contents are returned as a\nbuffer. Currently, the only available encoding is `utf8`, and\nspecifying that will cause the file contents to be returned as a string. For compatibility with the Node API, the `readFile` method will accept the string \"utf8\" instead of an Options object.\n\n## References\n\nThis library implements a subset of the [Node.js v10 promise-based FileHandle API](https://nodejs.org/api/fs.html#fs_class_filehandle).\n","readmeFilename":"README.md"}