Skip to content

Commit

Permalink
Added public access modifer to bare constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre committed Oct 1, 2024
1 parent 7e127a4 commit f18ec89
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 22 additions & 1 deletion src/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,50 +25,59 @@ function convertError(e: unknown, path: string = ''): ErrnoError {
}

export class EmscriptenFile extends File {
constructor(
public constructor(
protected fs: EmscriptenFS,
protected em: typeof FS,
public readonly path: string,
protected stream: FS.FSStream
) {
super();
}

public get position(): number {
return this.stream.position;
}

public async close(): Promise<void> {
return this.closeSync();
}

public closeSync(): void {
try {
this.em.close(this.stream);
} catch (e) {
throw convertError(e, this.path);
}
}

public async stat(): Promise<Stats> {
return this.statSync();
}

public statSync(): Stats {
try {
return this.fs.statSync(this.path);
} catch (e) {
throw convertError(e, this.path);
}
}

public async truncate(len: number): Promise<void> {
return this.truncateSync(len);
}

public truncateSync(len: number): void {
try {
this.em.ftruncate(this.stream.fd!, len);
} catch (e) {
throw convertError(e, this.path);
}
}

public async write(buffer: Buffer, offset: number, length: number, position: number): Promise<number> {
return this.writeSync(buffer, offset, length, position);
}

public writeSync(buffer: Buffer, offset: number, length: number, position?: number): number {
try {
// Emscripten is particular about what position is set to.
Expand All @@ -77,9 +86,11 @@ export class EmscriptenFile extends File {
throw convertError(e, this.path);
}
}

public async read<TBuffer extends ArrayBufferView>(buffer: TBuffer, offset: number, length: number, position: number): Promise<{ bytesRead: number; buffer: TBuffer }> {
return { bytesRead: this.readSync(buffer, offset, length, position), buffer };
}

public readSync(buffer: ArrayBufferView, offset: number, length: number, position?: number): number {
try {
// Emscripten is particular about what position is set to.
Expand All @@ -88,41 +99,51 @@ export class EmscriptenFile extends File {
throw convertError(e, this.path);
}
}

public async sync(): Promise<void> {
this.syncSync();
}

public syncSync(): void {
// NOP.
}

public async chown(uid: number, gid: number): Promise<void> {
return this.chownSync(uid, gid);
}

public chownSync(uid: number, gid: number): void {
try {
this.em.fchown(this.stream.fd!, uid, gid);
} catch (e) {
throw convertError(e, this.path);
}
}

public async chmod(mode: number): Promise<void> {
return this.chmodSync(mode);
}

public chmodSync(mode: number): void {
try {
this.em.fchmod(this.stream.fd!, mode);
} catch (e) {
throw convertError(e, this.path);
}
}

public async utimes(atime: Date, mtime: Date): Promise<void> {
return this.utimesSync(atime, mtime);
}

public utimesSync(atime: Date, mtime: Date): void {
this.fs.utimesSync(this.path, atime, mtime);
}

public async _setType(type: FileType): Promise<void> {

Check warning on line 143 in src/backend.ts

View workflow job for this annotation

GitHub Actions / CI / MacOS / CI

'type' is defined but never used

Check warning on line 143 in src/backend.ts

View workflow job for this annotation

GitHub Actions / CI / Windows / CI

'type' is defined but never used

Check warning on line 143 in src/backend.ts

View workflow job for this annotation

GitHub Actions / CI / Ubuntu / CI

'type' is defined but never used
throw ErrnoError.With('ENOSYS', this.path, '_setType');
}

public _setTypeSync(type: FileType): void {

Check warning on line 147 in src/backend.ts

View workflow job for this annotation

GitHub Actions / CI / MacOS / CI

'type' is defined but never used

Check warning on line 147 in src/backend.ts

View workflow job for this annotation

GitHub Actions / CI / Windows / CI

'type' is defined but never used

Check warning on line 147 in src/backend.ts

View workflow job for this annotation

GitHub Actions / CI / Ubuntu / CI

'type' is defined but never used
throw ErrnoError.With('ENOSYS', this.path, '_setType');
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface EmscriptenNodeFS {
* @see https://github.com/emscripten-core/emscripten/blob/main/src/library_nodefs.js
*/
export default class ZenEmscriptenNodeFS implements EmscriptenNodeFS {
constructor(
public constructor(
public readonly fs: typeof zfs = zfs,
public readonly em_fs: typeof EmFS,
protected path: {
Expand Down

0 comments on commit f18ec89

Please sign in to comment.