@@ -66,6 +66,7 @@ const {
6666const { opendir } = require ( 'internal/fs/dir' ) ;
6767const {
6868 parseFileMode,
69+ validateAbortSignal,
6970 validateBoolean,
7071 validateBuffer,
7172 validateInteger,
@@ -668,14 +669,16 @@ async function writeFile(path, data, options) {
668669 data = Buffer . from ( data , options . encoding || 'utf8' ) ;
669670 }
670671
672+ validateAbortSignal ( options . signal ) ;
671673 if ( path instanceof FileHandle )
672674 return writeFileHandle ( path , data , options . signal ) ;
673675
674- const fd = await open ( path , flag , options . mode ) ;
675676 if ( options . signal ?. aborted ) {
676677 throw lazyDOMException ( 'The operation was aborted' , 'AbortError' ) ;
677678 }
678- return PromisePrototypeFinally ( writeFileHandle ( fd , data ) , fd . close ) ;
679+
680+ const fd = await open ( path , flag , options . mode ) ;
681+ return PromisePrototypeFinally ( writeFileHandle ( fd , data , options . signal ) , fd . close ) ;
679682}
680683
681684async function appendFile ( path , data , options ) {
@@ -692,6 +695,10 @@ async function readFile(path, options) {
692695 if ( path instanceof FileHandle )
693696 return readFileHandle ( path , options ) ;
694697
698+ if ( options . signal ?. aborted ) {
699+ throw lazyDOMException ( 'The operation was aborted' , 'AbortError' ) ;
700+ }
701+
695702 const fd = await open ( path , flag , 0o666 ) ;
696703 return PromisePrototypeFinally ( readFileHandle ( fd , options ) , fd . close ) ;
697704}
0 commit comments