New:Socket for Asana Is Now Available.Learn more
Get Started

@yarnpkg/fslib

Package Overview
Dependencies
Maintainers
5
Versions
136
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@yarnpkg/fslib - npm Package Compare versions

Comparing version
3.1.3
to
3.1.4
+11
-32
lib/patchFs/FileHandle.d.ts

@@ -1,33 +0,6 @@

import type { BigIntStats, ReadStream, StatOptions, Stats, WriteStream, WriteVResult } from 'fs';
import type { Abortable } from 'events';
import type { FlagAndOpenMode, FileReadResult, FileReadOptions } from 'fs/promises';
import type { CreateReadStreamOptions, CreateWriteStreamOptions, FakeFS } from '../FakeFS';
import type { Path } from '../path';
interface ObjectEncodingOptions {
encoding?: BufferEncoding | null | undefined;
}
interface FlagAndOpenMode {
mode?: Mode | undefined;
flag?: OpenMode | undefined;
}
type OpenMode = number | string;
type Mode = number | string;
interface FileReadResult<T extends ArrayBufferView> {
bytesRead: number;
buffer: T;
}
interface FileReadOptions<T extends ArrayBufferView = Buffer> {
buffer?: T;
offset?: number | null;
length?: number | null;
position?: number | null;
}
interface ReadVResult {
bytesRead: number;
buffers: Array<NodeJS.ArrayBufferView>;
}
interface AbortSignal {
readonly aborted: boolean;
}
interface Abortable {
signal?: AbortSignal | undefined;
}
import type { BigIntStats, ObjectEncodingOptions, OpenMode, ReadStream, ReadVResult, StatOptions, Stats, WriteStream, WriteVResult } from 'fs';
type WriteArgsBuffer<TBuffer extends Uint8Array> = [

@@ -68,4 +41,10 @@ buffer: TBuffer,

sync(): Promise<void>;
read(options?: FileReadOptions<Buffer>): Promise<FileReadResult<Buffer>>;
read(buffer: Buffer, offset?: number | null, length?: number | null, position?: number | null): Promise<FileReadResult<Buffer>>;
read<T extends NodeJS.ArrayBufferView>(buffer: T, offset?: number | null, length?: number | null, position?: number | null): Promise<FileReadResult<T>>;
read<T extends NodeJS.ArrayBufferView>(buffer: T, options?: Omit<FileReadOptions<T>, `buffer`>): Promise<FileReadResult<T>>;
read<T extends NodeJS.ArrayBufferView = NonSharedBuffer>(options: FileReadOptions<T> & {
buffer: T;
}): Promise<FileReadResult<T>>;
read(options?: FileReadOptions<NonSharedBuffer> & {
buffer?: never;
}): Promise<FileReadResult<NonSharedBuffer>>;
readFile(options?: {

@@ -72,0 +51,0 @@ encoding?: null | undefined;

@@ -68,18 +68,28 @@ "use strict";

}
async read(bufferOrOptions, offset, length, position) {
async read(bufferOrOptions, offsetOrOptions, length, position) {
try {
this[kRef](this.read);
let buffer;
if (!Buffer.isBuffer(bufferOrOptions)) {
bufferOrOptions ??= {};
buffer = bufferOrOptions.buffer ?? Buffer.alloc(16384);
offset = bufferOrOptions.offset || 0;
length = bufferOrOptions.length ?? buffer.byteLength;
position = bufferOrOptions.position ?? null;
let offset;
if (!ArrayBuffer.isView(bufferOrOptions)) {
// read([options])
// TypeScript isn't able to infer that the coalescing happens only in the no-generic case
buffer = bufferOrOptions?.buffer ?? Buffer.alloc(16384);
offset = bufferOrOptions?.offset ?? 0;
length = bufferOrOptions?.length ?? buffer.byteLength - offset;
position = bufferOrOptions?.position ?? null;
}
else if (typeof offsetOrOptions === `object` && offsetOrOptions !== null) {
// read(buffer[, options])
buffer = bufferOrOptions;
offset = offsetOrOptions?.offset ?? 0;
length = offsetOrOptions?.length ?? buffer.byteLength - offset;
position = offsetOrOptions?.position ?? null;
}
else {
// read(buffer, offset[, length[, position]])
buffer = bufferOrOptions;
offset = offsetOrOptions ?? 0;
length ??= 0;
}
offset ??= 0;
length ??= 0;
if (length === 0) {

@@ -91,3 +101,5 @@ return {

}
const bytesRead = await this[kBaseFs].readPromise(this.fd, buffer, offset, length, position);
const bytesRead = await this[kBaseFs].readPromise(this.fd,
// FIXME: FakeFS should support ArrayBufferViews directly
Buffer.isBuffer(buffer) ? buffer : Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength), offset, length, position);
return {

@@ -94,0 +106,0 @@ bytesRead,

{
"name": "@yarnpkg/fslib",
"version": "3.1.3",
"version": "3.1.4",
"license": "BSD-2-Clause",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",