| 15 | writeFileSync(fn, 'Hello World'); |
| 16 | |
| 17 | async function readFileTest() { |
| 18 | const handle = await open(fn, 'r'); |
| 19 | |
| 20 | /* Read only five bytes, so that the position moves to five. */ |
| 21 | const buf = Buffer.alloc(5); |
| 22 | const { bytesRead } = await handle.read(buf, 0, 5, null); |
| 23 | assert.strictEqual(bytesRead, 5); |
| 24 | assert.strictEqual(buf.toString(), 'Hello'); |
| 25 | |
| 26 | /* readFile() should read from position five, instead of zero. */ |
| 27 | assert.strictEqual((await handle.readFile()).toString(), ' World'); |
| 28 | |
| 29 | await handle.close(); |
| 30 | } |
| 31 | |
| 32 | |
| 33 | readFileTest() |