1
1
import * as fs from "fs" ;
2
2
import { callbackify } from "util" ;
3
- import { ClientProxy } from "../../common/proxy" ;
3
+ import { ClientProxy , Batch } from "../../common/proxy" ;
4
4
import { IEncodingOptions , IEncodingOptionsCallback } from "../../common/util" ;
5
5
import { FsModuleProxy , Stats as IStats , WatcherProxy , WriteStreamProxy } from "../../node/modules/fs" ;
6
6
import { Writable } from "./stream" ;
7
7
8
8
// tslint:disable no-any
9
9
10
+ class StatBatch extends Batch < IStats , { path : fs . PathLike } > {
11
+ public constructor ( private readonly proxy : FsModuleProxy ) {
12
+ super ( ) ;
13
+ }
14
+
15
+ protected remoteCall ( batch : { path : fs . PathLike } [ ] ) : Promise < ( IStats | Error ) [ ] > {
16
+ return this . proxy . statBatch ( batch ) ;
17
+ }
18
+ }
19
+
20
+ class ReaddirBatch extends Batch < Buffer [ ] | fs . Dirent [ ] | string [ ] , { path : fs . PathLike , options : IEncodingOptions } > {
21
+ public constructor ( private readonly proxy : FsModuleProxy ) {
22
+ super ( ) ;
23
+ }
24
+
25
+ protected remoteCall ( queue : { path : fs . PathLike , options : IEncodingOptions } [ ] ) : Promise < ( Buffer [ ] | fs . Dirent [ ] | string [ ] | Error ) [ ] > {
26
+ return this . proxy . readdirBatch ( queue ) ;
27
+ }
28
+ }
29
+
10
30
class Watcher extends ClientProxy < WatcherProxy > implements fs . FSWatcher {
11
31
public close ( ) : void {
12
32
this . proxy . close ( ) ;
@@ -28,7 +48,13 @@ class WriteStream extends Writable<WriteStreamProxy> implements fs.WriteStream {
28
48
}
29
49
30
50
export class FsModule {
31
- public constructor ( private readonly proxy : FsModuleProxy ) { }
51
+ private readonly statBatch : StatBatch ;
52
+ private readonly readdirBatch : ReaddirBatch ;
53
+
54
+ public constructor ( private readonly proxy : FsModuleProxy ) {
55
+ this . statBatch = new StatBatch ( this . proxy ) ;
56
+ this . readdirBatch = new ReaddirBatch ( this . proxy ) ;
57
+ }
32
58
33
59
public access = ( path : fs . PathLike , mode : number | undefined | ( ( err : NodeJS . ErrnoException ) => void ) , callback ?: ( err : NodeJS . ErrnoException ) => void ) : void => {
34
60
if ( typeof mode === "function" ) {
@@ -175,7 +201,7 @@ export class FsModule {
175
201
callback = options ;
176
202
options = undefined ;
177
203
}
178
- callbackify ( this . proxy . readdir ) ( path , options , callback ! ) ;
204
+ callbackify ( this . readdirBatch . add ) ( { path, options } , callback ! ) ;
179
205
}
180
206
181
207
public readlink = ( path : fs . PathLike , options : IEncodingOptionsCallback , callback ?: ( err : NodeJS . ErrnoException , linkString : string | Buffer ) => void ) : void => {
@@ -203,7 +229,7 @@ export class FsModule {
203
229
}
204
230
205
231
public stat = ( path : fs . PathLike , callback : ( err : NodeJS . ErrnoException , stats : fs . Stats ) => void ) : void => {
206
- callbackify ( this . proxy . stat ) ( path , ( error , stats ) => {
232
+ callbackify ( this . statBatch . add ) ( { path } , ( error , stats ) => {
207
233
callback ( error , stats && new Stats ( stats ) ) ;
208
234
} ) ;
209
235
}
0 commit comments