You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: default to calculating speed over a range of time
BREAKING CHANGES:
- `new StreamSpeed(timeUnit)` - `new StreamSpeed({ timeUnit })`
- Speed is now calculated based on total data read over a range of
time, defaults to 1sec. Previously there were 2 speeds, current speed
and average speed. Current speed was calculated based on amount of
data received in latest read over the time difference between latest
read and last read.
- `speed` event now only emits one speed.
Copy file name to clipboardExpand all lines: README.md
+7-9Lines changed: 7 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ let ss = new StreamSpeed();
15
15
ss.add(rs);
16
16
17
17
// Listen for events emitted by streamspeed on the given stream.
18
-
ss.on('speed', (speed, avgSpeed) => {
18
+
ss.on('speed', (speed) => {
19
19
console.log('Reading at', speed, 'bytes per second');
20
20
});
21
21
```
@@ -28,16 +28,18 @@ group.add(stream1);
28
28
group.add(stream2);
29
29
group.add(stream3);
30
30
31
-
group.on('speed', (speed, avg) => {
31
+
group.on('speed', (speed) => {
32
32
console.log('now reading at', speed, 'bps');
33
33
});
34
34
```
35
35
36
36

37
37
38
38
# API
39
-
### new StreamSpeed([timeUnit])
40
-
A group that can be used to watch several streams. Will emit `speed` events. `timeUnit` defaults to `1000` for speed per second.
39
+
### new StreamSpeed([options])
40
+
A group that can be used to watch several streams. Will emit `speed` events. `options` can have the following properties,
41
+
-`timeUnit` - Defaults to `1000` for speed per second. If you want another unit such as per hour, use `1000 * 60 * 60`.
42
+
-`range` - The time in ms to use to calculate the speed over. Defaults to 1000. The longer this is, the longer it'll speed will ramp up and down until it stabilizes for a big readstream. The shorter it is, the more responsive it is to sudden speed changes.
41
43
42
44
### StreamSpeed#add(stream)
43
45
Adds stream to group.
@@ -51,9 +53,6 @@ Returns a list of all streams in the group.
51
53
### StreamSpeed#speed
52
54
Curent speed.
53
55
54
-
### StreamSpeed#avg
55
-
Current average speed.
56
-
57
56
### StreamSpeed.toHuman(bytes, options)
58
57
Convenient method to convert `bytes` to a human readable string.
0 commit comments