File tree 1 file changed +18
-4
lines changed
1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -75,9 +75,9 @@ export function readFile(
75
75
| string
76
76
| {
77
77
encoding ? : string | null ,
78
- // Ignored :
79
- flag ? : string ,
80
- signal ? : mixed ,
78
+ // Unsupported :
79
+ flag ? : string , // Doesn't make sense except "r"
80
+ signal ? : mixed , // We'll have our own signal
81
81
} ,
82
82
): string | Buffer {
83
83
const map = unstable_getCacheForType ( createReadFileCache ) ;
@@ -91,7 +91,21 @@ export function readFile(
91
91
if ( ! options ) {
92
92
return result ;
93
93
}
94
- const encoding = typeof options === 'string' ? options : options . encoding ;
94
+ let encoding ;
95
+ if ( typeof options === 'string' ) {
96
+ encoding = options ;
97
+ } else {
98
+ const flag = options . flag ;
99
+ if ( flag != null && flag !== 'r' ) {
100
+ throw Error (
101
+ 'The flag option is not supported, and always defaults to "r".' ,
102
+ ) ;
103
+ }
104
+ if ( options . signal ) {
105
+ throw Error ( 'The signal option is not supported.' ) ;
106
+ }
107
+ encoding = options . encoding ;
108
+ }
95
109
if ( typeof encoding !== 'string' ) {
96
110
return result ;
97
111
}
You can’t perform that action at this time.
0 commit comments