@@ -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,14 +669,23 @@ 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
674
- const fd = await open ( path , flag , options . mode ) ;
675
676
if ( options . signal ?. aborted ) {
676
677
throw lazyDOMException ( 'The operation was aborted' , 'AbortError' ) ;
677
678
}
678
- return PromisePrototypeFinally ( writeFileHandle ( fd , data ) , fd . close ) ;
679
+
680
+ const fd = await open ( path , flag , options . mode ) ;
681
+ try {
682
+ if ( options . signal ?. aborted ) {
683
+ throw lazyDOMException ( 'The operation was aborted' , 'AbortError' ) ;
684
+ }
685
+ await writeFileHandle ( fd , data ) ;
686
+ } finally {
687
+ await fd . close ( ) ;
688
+ }
679
689
}
680
690
681
691
async function appendFile ( path , data , options ) {
@@ -692,6 +702,10 @@ async function readFile(path, options) {
692
702
if ( path instanceof FileHandle )
693
703
return readFileHandle ( path , options ) ;
694
704
705
+ if ( options . signal ?. aborted ) {
706
+ throw lazyDOMException ( 'The operation was aborted' , 'AbortError' ) ;
707
+ }
708
+
695
709
const fd = await open ( path , flag , 0o666 ) ;
696
710
return PromisePrototypeFinally ( readFileHandle ( fd , options ) , fd . close ) ;
697
711
}
0 commit comments