From 334838c81f3b3ab79ccf9d83076d0c57fa092095 Mon Sep 17 00:00:00 2001 From: James Prevett Date: Mon, 11 Nov 2024 22:35:37 -0600 Subject: [PATCH] `PreloadFile._truncate` now uses `_write` instead of `writeSync` --- src/file.ts | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/file.ts b/src/file.ts index 19e4297c..d82d1397 100644 --- a/src/file.ts +++ b/src/file.ts @@ -166,12 +166,12 @@ export abstract class File { public abstract close(): Promise; public abstract closeSync(): void; - public [Symbol.asyncDispose](): Promise { - return this.close(); + public async [Symbol.asyncDispose](): Promise { + await this.close(); } public [Symbol.dispose](): void { - return this.closeSync(); + this.closeSync(); } public abstract truncate(len: number): Promise; @@ -427,12 +427,12 @@ export class PreloadFile extends File { if (length > this._buffer.length) { const data = new Uint8Array(length - this._buffer.length); // Write will set stats.size and handle syncing. - this.writeSync(data, 0, data.length, this._buffer.length); + this._write(data, 0, data.length, this._buffer.length); return; } this.stats.size = length; // Truncate. - this._buffer = this._buffer.slice(0, length); + this._buffer = length ? this._buffer.slice(0, length) : new Uint8Array(); } public async truncate(length: number): Promise { @@ -641,14 +641,6 @@ export class PreloadFile extends File { this.stats.mode = (this.stats.mode & ~S_IFMT) | type; this.syncSync(); } - - public async [Symbol.asyncDispose]() { - await this.close(); - } - - public [Symbol.dispose]() { - this.closeSync(); - } } /**