Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ed5f253

Browse filesBrowse files
danbevMylesBorins
authored andcommitted
stream: refactor getHighWaterMark in state.js
This commit aims to reduce some code duplication in state.js PR-URL: #20415 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent 4710349 commit ed5f253
Copy full SHA for ed5f253

File tree

Expand file treeCollapse file tree

1 file changed

+10
-10
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-10
lines changed
Open diff view settings
Collapse file

‎lib/internal/streams/state.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/state.js
+10-10Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
const { ERR_INVALID_OPT_VALUE } = require('internal/errors').codes;
44

5+
function highWaterMarkFrom(options, isDuplex, duplexKey) {
6+
return options.highWaterMark != null ? options.highWaterMark :
7+
isDuplex ? options[duplexKey] : null;
8+
}
9+
510
function getHighWaterMark(state, options, duplexKey, isDuplex) {
6-
let hwm = options.highWaterMark;
11+
const hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
712
if (hwm != null) {
8-
if (typeof hwm !== 'number' || !(hwm >= 0))
9-
throw new ERR_INVALID_OPT_VALUE('highWaterMark', hwm);
10-
return Math.floor(hwm);
11-
} else if (isDuplex) {
12-
hwm = options[duplexKey];
13-
if (hwm != null) {
14-
if (typeof hwm !== 'number' || !(hwm >= 0))
15-
throw new ERR_INVALID_OPT_VALUE(duplexKey, hwm);
16-
return Math.floor(hwm);
13+
if (!Number.isInteger(hwm) || hwm < 0) {
14+
const name = isDuplex ? duplexKey : 'highWaterMark';
15+
throw new ERR_INVALID_OPT_VALUE(name, hwm);
1716
}
17+
return Math.floor(hwm);
1818
}
1919

2020
// Default value

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.