xref: /third_party/node/test/parallel/test-fs-truncate-sync.js (revision 1cb0ef41)
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/parallel/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_cirequire('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst path = require('path');
51cb0ef41Sopenharmony_ciconst fs = require('fs');
61cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir');
71cb0ef41Sopenharmony_ciconst tmp = tmpdir.path;
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_citmpdir.refresh();
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst filename = path.resolve(tmp, 'truncate-sync-file.txt');
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_cifs.writeFileSync(filename, 'hello world', 'utf8');
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciconst fd = fs.openSync(filename, 'r+');
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_cifs.truncateSync(fd, 5);
181cb0ef41Sopenharmony_ciassert(fs.readFileSync(fd).equals(Buffer.from('hello')));
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_cifs.closeSync(fd);
211cb0ef41Sopenharmony_cifs.unlinkSync(filename);
22

Indexes created Thu Nov 07 10:32:03 CST 2024