Skip to content

Commit ed5f253

Browse 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

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

‎lib/internal/streams/state.js‎

Lines 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+
functionhighWaterMarkFrom(options,isDuplex,duplexKey){
6+
returnoptions.highWaterMark!=null ? options.highWaterMark :
7+
isDuplex ? options[duplexKey] : null;
8+
}
9+
510
functiongetHighWaterMark(state,options,duplexKey,isDuplex){
6-
lethwm=options.highWaterMark;
11+
consthwm=highWaterMarkFrom(options,isDuplex,duplexKey);
712
if(hwm!=null){
8-
if(typeofhwm!=='number'||!(hwm>=0))
9-
thrownewERR_INVALID_OPT_VALUE('highWaterMark',hwm);
10-
returnMath.floor(hwm);
11-
}elseif(isDuplex){
12-
hwm=options[duplexKey];
13-
if(hwm!=null){
14-
if(typeofhwm!=='number'||!(hwm>=0))
15-
thrownewERR_INVALID_OPT_VALUE(duplexKey,hwm);
16-
returnMath.floor(hwm);
13+
if(!Number.isInteger(hwm)||hwm<0){
14+
constname=isDuplex ? duplexKey : 'highWaterMark';
15+
thrownewERR_INVALID_OPT_VALUE(name,hwm);
1716
}
17+
returnMath.floor(hwm);
1818
}
1919

2020
// Default value

0 commit comments

Comments
 (0)