Skip to content

Commit

Permalink
Throw for unsupported
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Dec 9, 2020
1 parent f85a3cf commit 969d92b
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions packages/react-fs/src/ReactFilesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ export function readFile(
| string
| {
encoding?: string | null,
// Ignored:
flag?: string,
signal?: mixed,
// Unsupported:
flag?: string, // Doesn't make sense except "r"
signal?: mixed, // We'll have our own signal
},
): string | Buffer {
const map = unstable_getCacheForType(createReadFileCache);
Expand All @@ -91,7 +91,21 @@ export function readFile(
if (!options) {
return result;
}
const encoding = typeof options === 'string' ? options : options.encoding;
let encoding;
if (typeof options === 'string') {
encoding = options;
} else {
const flag = options.flag;
if (flag != null && flag !== 'r') {
throw Error(
'The flag option is not supported, and always defaults to "r".',
);
}
if (options.signal) {
throw Error('The signal option is not supported.');
}
encoding = options.encoding;
}
if (typeof encoding !== 'string') {
return result;
}
Expand Down

0 comments on commit 969d92b

Please sign in to comment.