Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/read-chunk
Read a chunk from a file
https://github.com/sindresorhus/read-chunk
Last synced: about 1 month ago
JSON representation
Read a chunk from a file
- Host: GitHub
- URL: https://github.com/sindresorhus/read-chunk
- Owner: sindresorhus
- License: mit
- Created: 2014-01-19T02:56:42.000Z (almost 11 years ago)
- Default Branch: main
- Last Pushed: 2022-08-28T14:35:19.000Z (about 2 years ago)
- Last Synced: 2024-04-13T17:52:35.955Z (7 months ago)
- Language: JavaScript
- Size: 27.3 KB
- Stars: 118
- Watchers: 7
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- Funding: .github/funding.yml
- License: license
- Security: .github/security.md
Awesome Lists containing this project
- awesome - sindresorhus/read-chunk - Read a chunk from a file (JavaScript)
README
# read-chunk
> Read a chunk from a file
Because the built-in way requires way too much boilerplate.
## Install
```sh
npm install read-chunk
```## Usage
```js
import {readChunk} from 'read-chunk';// foo.txt => hello
await readChunk('foo.txt', {length: 3, startPosition: 1});
//=> 'ell'
```## API
### readChunk(filePath, {length, startPosition})
Returns a `Promise` with the read chunk.
### readChunkSync(filePath, {length, startPosition})
Returns a `Uint8Array` with the read chunk.
#### filePath
Type: `string`
#### length
Type: `number`
The number of bytes to read.
#### startPosition
Type: `number`
The position to start reading from.