11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst fs = require('fs'); 41cb0ef41Sopenharmony_ciconst path = require('path'); 51cb0ef41Sopenharmony_ciconst assert = require('assert'); 61cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 71cb0ef41Sopenharmony_ciconst file = path.join(tmpdir.path, 'write_stream_filehandle_test.txt'); 81cb0ef41Sopenharmony_ciconst input = 'hello world'; 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_citmpdir.refresh(); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_cifs.promises.open(file, 'w+').then((handle) => { 131cb0ef41Sopenharmony_ci let calls = 0; 141cb0ef41Sopenharmony_ci const { 151cb0ef41Sopenharmony_ci write: originalWriteFunction, 161cb0ef41Sopenharmony_ci writev: originalWritevFunction 171cb0ef41Sopenharmony_ci } = handle; 181cb0ef41Sopenharmony_ci handle.write = function write() { 191cb0ef41Sopenharmony_ci calls++; 201cb0ef41Sopenharmony_ci return Reflect.apply(originalWriteFunction, this, arguments); 211cb0ef41Sopenharmony_ci }; 221cb0ef41Sopenharmony_ci handle.writev = function writev() { 231cb0ef41Sopenharmony_ci calls++; 241cb0ef41Sopenharmony_ci return Reflect.apply(originalWritevFunction, this, arguments); 251cb0ef41Sopenharmony_ci }; 261cb0ef41Sopenharmony_ci const stream = fs.createWriteStream(null, { fd: handle }); 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci stream.end(input); 291cb0ef41Sopenharmony_ci stream.on('close', common.mustCall(() => { 301cb0ef41Sopenharmony_ci assert(calls > 0, 'expected at least one call to fileHandle.write or ' + 311cb0ef41Sopenharmony_ci 'fileHandle.writev, got 0'); 321cb0ef41Sopenharmony_ci })); 331cb0ef41Sopenharmony_ci}).then(common.mustCall()); 34