Skip to content

Commit

Permalink
PreloadFile._truncate now uses _write instead of writeSync
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre committed Nov 12, 2024
1 parent 7ce5be1 commit 334838c
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ export abstract class File<FS extends FileSystem = FileSystem> {
public abstract close(): Promise<void>;
public abstract closeSync(): void;

public [Symbol.asyncDispose](): Promise<void> {
return this.close();
public async [Symbol.asyncDispose](): Promise<void> {
await this.close();
}

public [Symbol.dispose](): void {
return this.closeSync();
this.closeSync();
}

public abstract truncate(len: number): Promise<void>;
Expand Down Expand Up @@ -427,12 +427,12 @@ export class PreloadFile<FS extends FileSystem> extends File<FS> {
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<void> {
Expand Down Expand Up @@ -641,14 +641,6 @@ export class PreloadFile<FS extends FileSystem> extends File<FS> {
this.stats.mode = (this.stats.mode & ~S_IFMT) | type;
this.syncSync();
}

public async [Symbol.asyncDispose]() {
await this.close();
}

public [Symbol.dispose]() {
this.closeSync();
}
}

/**
Expand Down

0 comments on commit 334838c

Please sign in to comment.