mirror of
https://github.com/nodejs/node.git
synced 2025-04-29 22:40:57 +00:00

PR-URL: https://github.com/nodejs/node/pull/28858 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
31 lines
827 B
JavaScript
31 lines
827 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
// The following tests validate base functionality for the fs.promises
|
|
// FileHandle.readFile method.
|
|
|
|
const fs = require('fs');
|
|
const { open } = fs.promises;
|
|
const path = require('path');
|
|
const tmpdir = require('../common/tmpdir');
|
|
const assert = require('assert');
|
|
const tmpDir = tmpdir.path;
|
|
|
|
tmpdir.refresh();
|
|
|
|
async function validateWriteFile() {
|
|
const filePathForHandle = path.resolve(tmpDir, 'tmp-write-file2.txt');
|
|
const fileHandle = await open(filePathForHandle, 'w+');
|
|
const buffer = Buffer.from('Hello world'.repeat(100), 'utf8');
|
|
|
|
await fileHandle.writeFile(buffer);
|
|
const readFileData = fs.readFileSync(filePathForHandle);
|
|
assert.deepStrictEqual(buffer, readFileData);
|
|
|
|
await fileHandle.close();
|
|
}
|
|
|
|
validateWriteFile()
|
|
.then(common.mustCall());
|