UNPKG

822 BMarkdownView Raw
1# read-chunk [![Build Status](https://travis-ci.org/sindresorhus/read-chunk.svg?branch=master)](https://travis-ci.org/sindresorhus/read-chunk)
2
3> Read a chunk from a file
4
5Because the built-in way requires way too much boilerplate.
6
7
8## Install
9
10```
11$ npm install read-chunk
12```
13
14
15## Usage
16
17```js
18const readChunk = require('read-chunk');
19
20// foo.txt => hello
21
22readChunk.sync('foo.txt', 1, 3);
23//=> 'ell'
24```
25
26
27## API
28
29### readChunk(filePath, startPosition, length)
30
31Returns a `Promise<Buffer>` with the read chunk.
32
33### readChunk.sync(filePath, startPosition, length)
34
35Returns a `Buffer` with the read chunk.
36
37#### filePath
38
39Type: `string`
40
41#### startPosition
42
43Type: `number`
44
45Position to start reading.
46
47#### length
48
49Type: `number`
50
51Number of bytes to read.
52
53
54## License
55
56MIT © [Sindre Sorhus](https://sindresorhus.com)