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 |
|
5 | Because 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
|
18 | const readChunk = require('read-chunk');
|
19 |
|
20 | // foo.txt => hello
|
21 |
|
22 | readChunk.sync('foo.txt', 1, 3);
|
23 | //=> 'ell'
|
24 | ```
|
25 |
|
26 |
|
27 | ## API
|
28 |
|
29 | ### readChunk(filePath, startPosition, length)
|
30 |
|
31 | Returns a `Promise<Buffer>` with the read chunk.
|
32 |
|
33 | ### readChunk.sync(filePath, startPosition, length)
|
34 |
|
35 | Returns a `Buffer` with the read chunk.
|
36 |
|
37 | #### filePath
|
38 |
|
39 | Type: `string`
|
40 |
|
41 | #### startPosition
|
42 |
|
43 | Type: `number`
|
44 |
|
45 | Position to start reading.
|
46 |
|
47 | #### length
|
48 |
|
49 | Type: `number`
|
50 |
|
51 | Number of bytes to read.
|
52 |
|
53 |
|
54 | ## License
|
55 |
|
56 | MIT © [Sindre Sorhus](https://sindresorhus.com)
|