11import * as fs from "fs" ;
22import { callbackify } from "util" ;
3- import { ClientProxy , Batch } from "../../common/proxy" ;
3+ import { Batch , ClientProxy , ClientServerProxy } from "../../common/proxy" ;
44import { 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" ;
77
8- // tslint:disable no-any
9- // tslint:disable completed-docs
8+ // tslint:disable completed-docs no-any
109
1110class StatBatch extends Batch < IStats , { path : fs . PathLike } > {
1211 public constructor ( private readonly proxy : FsModuleProxy ) {
@@ -38,7 +37,9 @@ class ReaddirBatch extends Batch<Buffer[] | fs.Dirent[] | string[], { path: fs.P
3837 }
3938}
4039
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 {
4243 public close ( ) : void {
4344 this . catch ( this . proxy . close ( ) ) ;
4445 }
@@ -48,7 +49,25 @@ class Watcher extends ClientProxy<WatcherProxy> implements fs.FSWatcher {
4849 }
4950}
5051
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 {
5271 public get bytesWritten ( ) : number {
5372 throw new Error ( "not implemented" ) ;
5473 }
@@ -62,12 +81,18 @@ class WriteStream extends Writable<WriteStreamProxy> implements fs.WriteStream {
6281 }
6382}
6483
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+
6590export class FsModule {
6691 private readonly statBatch : StatBatch ;
6792 private readonly lstatBatch : LstatBatch ;
6893 private readonly readdirBatch : ReaddirBatch ;
6994
70- public constructor ( private readonly proxy : FsModuleProxy ) {
95+ public constructor ( private readonly proxy : ClientFsModuleProxy ) {
7196 this . statBatch = new StatBatch ( this . proxy ) ;
7297 this . lstatBatch = new LstatBatch ( this . proxy ) ;
7398 this . readdirBatch = new ReaddirBatch ( this . proxy ) ;
@@ -110,6 +135,10 @@ export class FsModule {
110135 ) ;
111136 }
112137
138+ public createReadStream = ( path : fs . PathLike , options ?: any ) : fs . ReadStream => {
139+ return new ReadStream ( this . proxy . createReadStream ( path , options ) ) ;
140+ }
141+
113142 public createWriteStream = ( path : fs . PathLike , options ?: any ) : fs . WriteStream => {
114143 return new WriteStream ( this . proxy . createWriteStream ( path , options ) ) ;
115144 }
0 commit comments