File tree 2 files changed +17
-1
lines changed
2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -199,7 +199,8 @@ export class FileHandle<P extends Path> {
199
199
data : string | Uint8Array ,
200
200
options ?: ( ObjectEncodingOptions & FlagAndOpenMode & Abortable ) | BufferEncoding | null ,
201
201
) : Promise < void > {
202
- throw new Error ( `Method not implemented.` ) ;
202
+ const encoding = ( typeof options === `string` ? options : options ?. encoding ) ?? undefined ;
203
+ return this . _baseFs . writeFilePromise ( this . fd , data , encoding ) ;
203
204
}
204
205
205
206
async write ( ...args : WriteArgsString ) : Promise < { bytesWritten : number , buffer : string } >
Original file line number Diff line number Diff line change @@ -341,6 +341,21 @@ describe(`patchedFs`, () => {
341
341
} ) ;
342
342
} ) ;
343
343
344
+ it ( `should support FileHandle.writeFile` , async ( ) => {
345
+ const patchedFs = extendFs ( fs , new PosixFS ( new NodeFS ( ) ) ) ;
346
+
347
+ await xfs . mktempPromise ( async dir => {
348
+ const filepath = npath . join ( npath . fromPortablePath ( dir ) , `foo.txt` ) ;
349
+
350
+ const fd = await patchedFs . promises . open ( filepath , `w` ) ;
351
+ await fd . writeFile ( `foo` ) ;
352
+ await fd . writeFile ( `bar` ) ;
353
+ await fd . close ( ) ;
354
+
355
+ await expect ( patchedFs . promises . readFile ( filepath , `utf8` ) ) . resolves . toEqual ( `foobar` ) ;
356
+ } ) ;
357
+ } ) ;
358
+
344
359
it ( `should support FileHandle.appendFile` , async ( ) => {
345
360
const patchedFs = extendFs ( fs , new PosixFS ( new NodeFS ( ) ) ) ;
346
361
You can’t perform that action at this time.
0 commit comments