Socket
Socket
Sign inDemoInstall

read-chunk

Package Overview
Dependencies
Maintainers
0
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

read-chunk - npm Package Compare versions

Comparing version 4.0.3 to 5.0.0

10

index.d.ts

@@ -1,4 +0,2 @@

import {Buffer} from 'node:buffer';
export interface Options {
export type Options = {
/**

@@ -15,3 +13,3 @@ The number of bytes to read.

readonly startPosition?: number | bigint;
}
};

@@ -34,3 +32,3 @@ /**

*/
export function readChunk(filePath: string, options: Options): Promise<Buffer>;
export function readChunk(filePath: string, options: Options): Promise<Uint8Array>;

@@ -53,2 +51,2 @@ /**

*/
export function readChunkSync(filePath: string, options: Options): Buffer;
export function readChunkSync(filePath: string, options: Options): Uint8Array;

26

index.js

@@ -1,16 +0,10 @@

import {promisify} from 'node:util';
import fs from 'node:fs';
import {Buffer} from 'node:buffer';
import pify from 'pify';
import {closeSync, openSync, readSync} from 'node:fs';
import {open} from 'node:fs/promises';
const fsReadP = pify(fs.read, {multiArgs: true});
const fsOpenP = promisify(fs.open);
const fsCloseP = promisify(fs.close);
export async function readChunk(filePath, {length, startPosition}) {
const fileDescriptor = await fsOpenP(filePath, 'r');
const fileDescriptor = await open(filePath, 'r');
try {
let [bytesRead, buffer] = await fsReadP(fileDescriptor, {
buffer: Buffer.alloc(length),
let {bytesRead, buffer} = await fileDescriptor.read({
buffer: new Uint8Array(length),
length,

@@ -26,3 +20,3 @@ position: startPosition,

} finally {
await fsCloseP(fileDescriptor);
await fileDescriptor?.close();
}

@@ -32,7 +26,7 @@ }

export function readChunkSync(filePath, {length, startPosition}) {
let buffer = Buffer.alloc(length);
const fileDescriptor = fs.openSync(filePath, 'r');
let buffer = new Uint8Array(length);
const fileDescriptor = openSync(filePath, 'r');
try {
const bytesRead = fs.readSync(fileDescriptor, buffer, {
const bytesRead = readSync(fileDescriptor, buffer, {
length,

@@ -48,4 +42,4 @@ position: startPosition,

} finally {
fs.closeSync(fileDescriptor);
closeSync(fileDescriptor);
}
}
{
"name": "read-chunk",
"version": "4.0.3",
"version": "5.0.0",
"description": "Read a chunk from a file",

@@ -14,5 +14,9 @@ "license": "MIT",

"type": "module",
"exports": "./index.js",
"exports": {
"types": "./index.d.ts",
"default": "./index.js"
},
"sideEffects": false,
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
"node": ">=18"
},

@@ -40,12 +44,9 @@ "scripts": {

],
"dependencies": {
"pify": "^5.0.0"
},
"devDependencies": {
"@types/node": "^16.4.13",
"ava": "^3.15.0",
"sinon": "^11.1.2",
"tsd": "^0.17.0",
"xo": "^0.44.0"
"ava": "^6.1.3",
"sinon": "^18.0.0",
"tsd": "^0.31.1",
"uint8array-extras": "^1.1.0",
"xo": "^0.58.0"
}
}

@@ -9,5 +9,5 @@ # read-chunk

```sh
npm install read-chunk
```
$ npm install read-chunk
```

@@ -29,7 +29,7 @@ ## Usage

Returns a `Promise<Buffer>` with the read chunk.
Returns a `Promise<Uint8Array>` with the read chunk.
### readChunkSync(filePath, {length, startPosition})
Returns a `Buffer` with the read chunk.
Returns a `Uint8Array` with the read chunk.

@@ -50,2 +50,2 @@ #### filePath

The poosition to start reading from.
The position to start reading from.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc