Read a chunk from a file
JavaScript
Switch branches/tags
Latest commit 691fbce Apr 21, 2016 @sindresorhus 2.0.0
Permalink
Failed to load latest commit information.
.editorconfig tweaks Oct 5, 2015
.gitattributes init Jan 19, 2014
.gitignore init Jan 19, 2014
.travis.yml ES2015ify and use promises (#3) Apr 20, 2016
fixture init Jan 19, 2014
index.js simplify the implementation (#4) Apr 21, 2016
license tweaks Aug 13, 2014
package.json 2.0.0 Apr 21, 2016
readme.md minor doc tweaks Apr 21, 2016
test.js ES2015ify and use promises (#3) Apr 20, 2016

readme.md

read-chunk Build Status

Read a chunk from a file

Because the built-in way is too much boilerplate.

Install

$ npm install --save read-chunk

Usage

const readChunk = require('read-chunk');

// foo.txt => hello

readChunk.sync('foo.txt', 1, 3);
//=> 'ell'

API

readChunk(filepath, position, length)

Returns a promise for a buffer.

readChunk.sync(filepath, position, length)

Returns a buffer.

filepath

Type: string

position

Type: number

Position to start reading.

length

Type: number

Number of bytes to read.

License

MIT © Sindre Sorhus