1
1
import * as fs from "fs" ;
2
2
import { callbackify } from "util" ;
3
- import { ClientProxy , Batch } from "../../common/proxy" ;
3
+ import { Batch , ClientProxy , ClientServerProxy } from "../../common/proxy" ;
4
4
import { IEncodingOptions , IEncodingOptionsCallback } from "../../common/util" ;
5
- import { FsModuleProxy , Stats as IStats , WatcherProxy , WriteStreamProxy } from "../../node/modules/fs" ;
6
- import { Writable } from "./stream" ;
5
+ import { FsModuleProxy , ReadStreamProxy , Stats as IStats , WatcherProxy , WriteStreamProxy } from "../../node/modules/fs" ;
6
+ import { Readable , Writable } from "./stream" ;
7
7
8
- // tslint:disable no-any
9
- // tslint:disable completed-docs
8
+ // tslint:disable completed-docs no-any
10
9
11
10
class StatBatch extends Batch < IStats , { path : fs . PathLike } > {
12
11
public constructor ( private readonly proxy : FsModuleProxy ) {
@@ -38,7 +37,9 @@ class ReaddirBatch extends Batch<Buffer[] | fs.Dirent[] | string[], { path: fs.P
38
37
}
39
38
}
40
39
41
- class Watcher extends ClientProxy < WatcherProxy > implements fs . FSWatcher {
40
+ interface ClientWatcherProxy extends WatcherProxy , ClientServerProxy < fs . FSWatcher > { }
41
+
42
+ class Watcher extends ClientProxy < ClientWatcherProxy > implements fs . FSWatcher {
42
43
public close ( ) : void {
43
44
this . catch ( this . proxy . close ( ) ) ;
44
45
}
@@ -48,7 +49,25 @@ class Watcher extends ClientProxy<WatcherProxy> implements fs.FSWatcher {
48
49
}
49
50
}
50
51
51
- class WriteStream extends Writable < WriteStreamProxy > implements fs . WriteStream {
52
+ interface ClientReadStreamProxy extends ReadStreamProxy , ClientServerProxy < fs . ReadStream > { }
53
+
54
+ class ReadStream extends Readable < ClientReadStreamProxy > implements fs . ReadStream {
55
+ public get bytesRead ( ) : number {
56
+ throw new Error ( "not implemented" ) ;
57
+ }
58
+
59
+ public get path ( ) : string | Buffer {
60
+ throw new Error ( "not implemented" ) ;
61
+ }
62
+
63
+ public close ( ) : void {
64
+ this . catch ( this . proxy . close ( ) ) ;
65
+ }
66
+ }
67
+
68
+ interface ClientWriteStreamProxy extends WriteStreamProxy , ClientServerProxy < fs . WriteStream > { }
69
+
70
+ class WriteStream extends Writable < ClientWriteStreamProxy > implements fs . WriteStream {
52
71
public get bytesWritten ( ) : number {
53
72
throw new Error ( "not implemented" ) ;
54
73
}
@@ -62,12 +81,18 @@ class WriteStream extends Writable<WriteStreamProxy> implements fs.WriteStream {
62
81
}
63
82
}
64
83
84
+ interface ClientFsModuleProxy extends FsModuleProxy , ClientServerProxy {
85
+ createReadStream ( path : fs . PathLike , options ?: any ) : Promise < ClientReadStreamProxy > ;
86
+ createWriteStream ( path : fs . PathLike , options ?: any ) : Promise < ClientWriteStreamProxy > ;
87
+ watch ( filename : fs . PathLike , options ?: IEncodingOptions ) : Promise < ClientWatcherProxy > ;
88
+ }
89
+
65
90
export class FsModule {
66
91
private readonly statBatch : StatBatch ;
67
92
private readonly lstatBatch : LstatBatch ;
68
93
private readonly readdirBatch : ReaddirBatch ;
69
94
70
- public constructor ( private readonly proxy : FsModuleProxy ) {
95
+ public constructor ( private readonly proxy : ClientFsModuleProxy ) {
71
96
this . statBatch = new StatBatch ( this . proxy ) ;
72
97
this . lstatBatch = new LstatBatch ( this . proxy ) ;
73
98
this . readdirBatch = new ReaddirBatch ( this . proxy ) ;
@@ -110,6 +135,10 @@ export class FsModule {
110
135
) ;
111
136
}
112
137
138
+ public createReadStream = ( path : fs . PathLike , options ?: any ) : fs . ReadStream => {
139
+ return new ReadStream ( this . proxy . createReadStream ( path , options ) ) ;
140
+ }
141
+
113
142
public createWriteStream = ( path : fs . PathLike , options ?: any ) : fs . WriteStream => {
114
143
return new WriteStream ( this . proxy . createWriteStream ( path , options ) ) ;
115
144
}
0 commit comments