Skip to content

Commit b630b77

Browse files
committed
Batch lstat
1 parent 6274f17 commit b630b77

File tree

2 files changed

+17
-1
lines changed
  • packages/protocol/src

2 files changed

+17
-1
lines changed

packages/protocol/src/browser/modules/fs.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ class StatBatch extends Batch<IStats, { path: fs.PathLike }> {
1717
}
1818
}
1919

20+
class LstatBatch extends Batch<IStats, { path: fs.PathLike }> {
21+
public constructor(private readonly proxy: FsModuleProxy) {
22+
super();
23+
}
24+
25+
protected remoteCall(batch: { path: fs.PathLike }[]): Promise<(IStats | Error)[]> {
26+
return this.proxy.lstatBatch(batch);
27+
}
28+
}
29+
2030
class ReaddirBatch extends Batch<Buffer[] | fs.Dirent[] | string[], { path: fs.PathLike, options: IEncodingOptions }> {
2131
public constructor(private readonly proxy: FsModuleProxy) {
2232
super();
@@ -49,10 +59,12 @@ class WriteStream extends Writable<WriteStreamProxy> implements fs.WriteStream {
4959

5060
export class FsModule {
5161
private readonly statBatch: StatBatch;
62+
private readonly lstatBatch: LstatBatch;
5263
private readonly readdirBatch: ReaddirBatch;
5364

5465
public constructor(private readonly proxy: FsModuleProxy) {
5566
this.statBatch = new StatBatch(this.proxy);
67+
this.lstatBatch = new LstatBatch(this.proxy);
5668
this.readdirBatch = new ReaddirBatch(this.proxy);
5769
}
5870

@@ -148,7 +160,7 @@ export class FsModule {
148160
}
149161

150162
public lstat = (path: fs.PathLike, callback: (err: NodeJS.ErrnoException, stats: fs.Stats) => void): void => {
151-
callbackify(this.proxy.lstat)(path, (error, stats) => {
163+
callbackify(this.lstatBatch.add)({ path }, (error, stats) => {
152164
callback(error, stats && new Stats(stats));
153165
});
154166
}

packages/protocol/src/node/modules/fs.ts

+4
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ export class FsModuleProxy {
156156
return this.makeStatsSerializable(await promisify(fs.lstat)(path));
157157
}
158158

159+
public async lstatBatch(args: { path: fs.PathLike }[]): Promise<(Stats | Error)[]> {
160+
return Promise.all(args.map((args) => this.lstat(args.path).catch((e) => e)));
161+
}
162+
159163
public mkdir(path: fs.PathLike, mode: number | string | fs.MakeDirectoryOptions | undefined | null): Promise<void> {
160164
return promisify(fs.mkdir)(path, mode);
161165
}

0 commit comments

Comments
 (0)