MCPcopy Index your code
hub / github.com/nodejs/node / writeFileTest

Function writeFileTest

test/parallel/test-fs-promises-writefile-with-fd.js:16–31  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14const fn = tmpdir.resolve('test.txt');
15
16async function writeFileTest() {
17 const handle = await open(fn, 'w');
18
19 /* Write only five bytes, so that the position moves to five. */
20 const buf = Buffer.from('Hello');
21 const { bytesWritten } = await handle.write(buf, 0, 5, null);
22 assert.strictEqual(bytesWritten, 5);
23
24 /* Write some more with writeFile(). */
25 await handle.writeFile('World');
26
27 /* New content should be written at position five, instead of zero. */
28 assert.strictEqual(readFileSync(fn).toString(), 'HelloWorld');
29
30 await handle.close();
31}
32
33
34writeFileTest()

Calls 7

openFunction · 0.70
closeMethod · 0.65
readFileSyncFunction · 0.50
fromMethod · 0.45
writeMethod · 0.45
writeFileMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…