Skip to content

Commit

Permalink
stream: throw on invalid args
Browse files Browse the repository at this point in the history
  • Loading branch information
mmomtchev committed Dec 2, 2020
1 parent 96d0198 commit 7095132
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/internal/fs/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const {
getOptions,
} = require('internal/fs/utils');
const { Readable, Writable, finished } = require('stream');
const { FileHandle } = require('internal/fs/promises');
const { toPathIfFileURL } = require('internal/url');
const kIoDone = Symbol('kIoDone');
const kIsPerformingIO = Symbol('kIsPerformingIO');
Expand Down Expand Up @@ -123,7 +124,7 @@ function importFd(stream, options) {
// another one
// https://github.com/nodejs/node/issues/35862
stream.fd = options.fd;
} else {
} else if (typeof options.fd === 'object' && options.fd instanceof FileHandle) {
// When fd is a FileHandle we can listen for 'close' events
if (options.fs)
// FileHandle is not supported with custom fs operations
Expand All @@ -133,7 +134,8 @@ function importFd(stream, options) {
stream[kFs] = FileHandleOperations(stream[kHandle]);
stream[kHandle][kRef]();
options.fd.on('close', FunctionPrototypeBind(stream.close, stream));
}
} else
throw ERR_INVALID_ARG_TYPE('options.fd', ['number', 'FileHandle'], options.fd);
}
}

Expand Down

0 comments on commit 7095132

Please sign in to comment.