Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cc04d53

Browse files
committedApr 23, 2022
feat: FileHandle.writeFile
1 parent a8feb13 commit cc04d53

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
 

‎packages/yarnpkg-fslib/sources/patchFs/FileHandle.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ export class FileHandle<P extends Path> {
199199
data: string | Uint8Array,
200200
options?: (ObjectEncodingOptions & FlagAndOpenMode & Abortable) | BufferEncoding | null,
201201
): 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);
203204
}
204205

205206
async write(...args: WriteArgsString): Promise<{ bytesWritten: number, buffer: string }>

‎packages/yarnpkg-fslib/tests/patchedFs.test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,21 @@ describe(`patchedFs`, () => {
341341
});
342342
});
343343

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+
344359
it(`should support FileHandle.appendFile`, async () => {
345360
const patchedFs = extendFs(fs, new PosixFS(new NodeFS()));
346361

0 commit comments

Comments
 (0)
Please sign in to comment.