Skip to content
This repository was archived by the owner on May 20, 2024. It is now read-only.

Commit 3a8dd8c

Browse files
committed
refactor: _read should proceed only when res is not undefined or null
1 parent e0fd515 commit 3a8dd8c

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

index.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,22 @@ class AWSApiReadStream extends Readable {
1111
async _read(size) {
1212
try {
1313
const res = await this._fn(this._nextToken)
14-
if (this._isInBufferMode()) {
15-
this._buffer.push(res)
16-
}
14+
if (res) {
15+
if (this._isInBufferMode()) {
16+
this._buffer.push(res)
17+
}
1718

18-
this.push(res)
19+
this.push(res)
1920

20-
if (res && res.NextToken !== undefined) {
21-
this._nextToken = res.NextToken
22-
return
23-
}
21+
if (res.NextToken !== undefined) {
22+
this._nextToken = res.NextToken
23+
return
24+
}
2425

25-
if (res && res.NextContinuationToken !== undefined) {
26-
this._nextToken = res.NextContinuationToken
27-
return
26+
if (res.NextContinuationToken !== undefined) {
27+
this._nextToken = res.NextContinuationToken
28+
return
29+
}
2830
}
2931

3032
this.push(null)
@@ -33,6 +35,11 @@ class AWSApiReadStream extends Readable {
3335
}
3436
}
3537

38+
stop() {
39+
this._stop = true
40+
this.destroy()
41+
}
42+
3643
static from(fn, { nextToken, options } = {}) {
3744
return new AWSApiReadStream(fn, options, nextToken)
3845
}

0 commit comments

Comments
 (0)