read-chunk
Advanced tools
Comparing version 3.0.0 to 3.1.0
11
index.js
@@ -8,7 +8,7 @@ 'use strict'; | ||
module.exports = (filePath, position, length) => { | ||
const readChunk = (filePath, startPosition, length) => { | ||
const buffer = Buffer.alloc(length); | ||
return withOpenFile(filePath, 'r', fileDescriptor => | ||
fsReadP(fileDescriptor, buffer, 0, length, position) | ||
fsReadP(fileDescriptor, buffer, 0, length, startPosition) | ||
) | ||
@@ -24,7 +24,10 @@ .then(([bytesRead, buffer]) => { | ||
module.exports.sync = (filePath, position, length) => { | ||
module.exports = readChunk; | ||
module.exports.default = readChunk; | ||
module.exports.sync = (filePath, startPosition, length) => { | ||
let buffer = Buffer.alloc(length); | ||
const bytesRead = withOpenFile.sync(filePath, 'r', fileDescriptor => | ||
fs.readSync(fileDescriptor, buffer, 0, length, position) | ||
fs.readSync(fileDescriptor, buffer, 0, length, startPosition) | ||
); | ||
@@ -31,0 +34,0 @@ |
{ | ||
"name": "read-chunk", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Read a chunk from a file", | ||
@@ -16,6 +16,7 @@ "license": "MIT", | ||
"scripts": { | ||
"test": "xo && ava" | ||
"test": "xo && ava && tsd-check" | ||
}, | ||
"files": [ | ||
"index.js" | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
@@ -37,10 +38,12 @@ "keywords": [ | ||
"dependencies": { | ||
"pify": "^4.0.0", | ||
"with-open-file": "^0.1.3" | ||
"pify": "^4.0.1", | ||
"with-open-file": "^0.1.5" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"sinon": "^6.1.5", | ||
"xo": "*" | ||
"@types/node": "^11.10.4", | ||
"ava": "^1.3.1", | ||
"sinon": "^7.2.7", | ||
"tsd-check": "^0.3.0", | ||
"xo": "^0.24.0" | ||
} | ||
} |
@@ -29,15 +29,15 @@ # read-chunk [![Build Status](https://travis-ci.org/sindresorhus/read-chunk.svg?branch=master)](https://travis-ci.org/sindresorhus/read-chunk) | ||
### readChunk(filepath, position, length) | ||
### readChunk(filePath, startPosition, length) | ||
Returns a `Promise<Buffer>`. | ||
Returns a `Promise<Buffer>` with the read chunk. | ||
### readChunk.sync(filepath, position, length) | ||
### readChunk.sync(filePath, startPosition, length) | ||
Returns a `Buffer`. | ||
Returns a `Buffer` with the read chunk. | ||
#### filepath | ||
#### filePath | ||
Type: `string` | ||
#### position | ||
#### startPosition | ||
@@ -44,0 +44,0 @@ Type: `number` |
4279
5
51
5
Updatedpify@^4.0.1
Updatedwith-open-file@^0.1.5