bandwidth-throttle-stream
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -0,1 +1,4 @@ | ||
# 1.1.1 | ||
- Fixes an issue where the throttle ended early with incomplete throughput, if the incoming data rate slows such that the outgoing data must wait. | ||
# 1.1.0 | ||
@@ -2,0 +5,0 @@ - Fixes issues when passing requests through an unbounded throttle (`bytesPerSecond` = `Infinity`). |
@@ -25,3 +25,3 @@ import Config from './Config'; | ||
private config; | ||
private isInFlight; | ||
private isDataBeingWritten; | ||
private handleRequestStart; | ||
@@ -28,0 +28,0 @@ private handleRequestStop; |
@@ -65,3 +65,3 @@ "use strict"; | ||
this.pendingBytesReadIndex = 0; | ||
this.isInFlight = false; | ||
this.isDataBeingWritten = false; | ||
this.done = deferred_1.default(); | ||
@@ -100,5 +100,8 @@ this.config = config; | ||
} | ||
// If there is more data to be processed, or there is no pending data but we are | ||
// unthrottled, stop here | ||
// Do not complete if: | ||
// - additional data is available to be processed, | ||
// - or, no additional data is available, but not all data has been written yet | ||
// - or, we are unthrottled | ||
if (this.pendingBytesReadIndex < this.pendingBytesCount || | ||
this.isDataBeingWritten || | ||
!this.config.isThrottled) | ||
@@ -110,3 +113,2 @@ return bytesToPushLength; | ||
this.destroy(); | ||
this.isInFlight = false; | ||
return bytesToPushLength; | ||
@@ -129,3 +131,3 @@ } | ||
transform(chunk) { | ||
if (!this.isInFlight) { | ||
if (!this.isDataBeingWritten) { | ||
// If this is the first chunk of data to be processed, or | ||
@@ -135,3 +137,3 @@ // if is processing was previously paused due to a lack of | ||
this.handleRequestStart(this); | ||
this.isInFlight = true; | ||
this.isDataBeingWritten = true; | ||
} | ||
@@ -153,2 +155,3 @@ this.pendingBytesBuffer.set(chunk, this.pendingBytesCount); | ||
// If an empty request was passed through the throttle, end immediately | ||
this.isDataBeingWritten = false; | ||
if (this.pendingBytesCount === 0) | ||
@@ -161,3 +164,2 @@ return; | ||
this.destroy(); | ||
this.isInFlight = false; | ||
return; | ||
@@ -164,0 +166,0 @@ } |
{ | ||
"name": "bandwidth-throttle-stream", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "A Node.js and Deno transform stream for throttling bandwidth", | ||
@@ -5,0 +5,0 @@ "author": "KunkaLabs Limited", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
70901
974