Skip to content

Commit

Permalink
Drop pify dependency (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornstar authored Jun 28, 2024
1 parent f01c7c3 commit eab5664
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
matrix:
node-version:
- 20
- 18
- 16
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand Down
21 changes: 8 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import {promisify} from 'node:util';
import fs from 'node:fs';
import pify from 'pify';

const fsReadP = pify(fs.read, {multiArgs: true});
const fsOpenP = promisify(fs.open);
const fsCloseP = promisify(fs.close);
import {closeSync, openSync, readSync} from 'node:fs';
import {open} from 'node:fs/promises';

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, {
let {bytesRead, buffer} = await fileDescriptor.read({
buffer: new Uint8Array(length),
length,
position: startPosition,
Expand All @@ -22,16 +17,16 @@ export async function readChunk(filePath, {length, startPosition}) {

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

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

try {
const bytesRead = fs.readSync(fileDescriptor, buffer, {
const bytesRead = readSync(fileDescriptor, buffer, {
length,
position: startPosition,
});
Expand All @@ -42,6 +37,6 @@ export function readChunkSync(filePath, {length, startPosition}) {

return buffer;
} finally {
fs.closeSync(fileDescriptor);
closeSync(fileDescriptor);
}
}
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"type": "module",
"exports": "./index.js",
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
"node": ">=16.0.0"
},
"scripts": {
"test": "xo && ava && tsd"
Expand All @@ -36,9 +36,6 @@
"fd",
"open"
],
"dependencies": {
"pify": "^5.0.0"
},
"devDependencies": {
"@types/node": "^16.4.13",
"ava": "^6.1.3",
Expand Down

0 comments on commit eab5664

Please sign in to comment.