mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
74e0ca3f49
PR-URL: https://github.com/nodejs/node/pull/49125 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
27 lines
716 B
JavaScript
27 lines
716 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { open, readFile } = require('fs').promises;
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
tmpdir.refresh();
|
|
|
|
async function validateTruncate() {
|
|
const text = 'Hello world';
|
|
const filename = tmpdir.resolve('truncate-file.txt');
|
|
const fileHandle = await open(filename, 'w+');
|
|
|
|
const buffer = Buffer.from(text, 'utf8');
|
|
await fileHandle.write(buffer, 0, buffer.length);
|
|
|
|
assert.strictEqual((await readFile(filename)).toString(), text);
|
|
|
|
await fileHandle.truncate(5);
|
|
assert.strictEqual((await readFile(filename)).toString(), 'Hello');
|
|
|
|
await fileHandle.close();
|
|
}
|
|
|
|
validateTruncate().then(common.mustCall());
|