@@ -66,6 +66,7 @@ const {
66
66
const { opendir } = require ( 'internal/fs/dir' ) ;
67
67
const {
68
68
parseFileMode,
69
+ validateAbortSignal,
69
70
validateBoolean,
70
71
validateBuffer,
71
72
validateInteger,
@@ -668,11 +669,17 @@ async function writeFile(path, data, options) {
668
669
data = Buffer . from ( data , options . encoding || 'utf8' ) ;
669
670
}
670
671
672
+ validateAbortSignal ( options . signal ) ;
671
673
if ( path instanceof FileHandle )
672
674
return writeFileHandle ( path , data , options . signal ) ;
673
675
676
+ if ( options . signal ?. aborted ) {
677
+ throw lazyDOMException ( 'The operation was aborted' , 'AbortError' ) ;
678
+ }
679
+
674
680
const fd = await open ( path , flag , options . mode ) ;
675
681
if ( options . signal ?. aborted ) {
682
+ await fd . close ( ) ;
676
683
throw lazyDOMException ( 'The operation was aborted' , 'AbortError' ) ;
677
684
}
678
685
return PromisePrototypeFinally ( writeFileHandle ( fd , data ) , fd . close ) ;
@@ -692,6 +699,10 @@ async function readFile(path, options) {
692
699
if ( path instanceof FileHandle )
693
700
return readFileHandle ( path , options ) ;
694
701
702
+ if ( options . signal ?. aborted ) {
703
+ throw lazyDOMException ( 'The operation was aborted' , 'AbortError' ) ;
704
+ }
705
+
695
706
const fd = await open ( path , flag , 0o666 ) ;
696
707
return PromisePrototypeFinally ( readFileHandle ( fd , options ) , fd . close ) ;
697
708
}
0 commit comments