File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -50,6 +50,9 @@ Removes stream from group.
5050### StreamSpeed#getSpeed()
5151Get current speed.
5252
53+ ### StreamSpeed#getStreamSpeed(stream)
54+ Get an individual's stream's current speed.
55+
5356### StreamSpeed#getStreams()
5457Returns a list of all streams in the group.
5558
@@ -60,7 +63,7 @@ Helper method to convert `bytes` to a human readable string.
6063StreamSpeed .toHuman (1500 ); // 1.46KB
6164StreamSpeed .toHuman (1024 * 1024 ); // 1MB
6265StreamSpeed .toHuman (1024 * 1024 * 20.5 , { timeUnit: ' s' }); // 20.5MB/s
63- StreamSpeed .toHuman (1024 * 1024 * 20.5 , { precision: 3 }); // 20.50MB
66+ StreamSpeed .toHuman (1024 * 1024 * 20.5 , { precision: 3 }); // 20.50MB
6467```
6568
6669### Event: 'speed'
Original file line number Diff line number Diff line change @@ -120,6 +120,20 @@ module.exports = class StreamSpeed extends EventEmitter {
120120 }
121121
122122
123+ /**
124+ * Get an individual stream's speed.
125+ *
126+ * @param {Readable } stream
127+ */
128+ getStreamSpeed ( stream ) {
129+ const meta = this . _streams . find ( m => m . stream === stream ) ;
130+ if ( ! meta ) {
131+ throw Error ( 'Stream not found in group' ) ;
132+ }
133+ return meta . speedo . getSpeed ( ) ;
134+ }
135+
136+
123137 /**
124138 * Converts bytes to human readable unit.
125139 * Thank you Amir from StackOverflow.
Original file line number Diff line number Diff line change @@ -48,6 +48,9 @@ describe('Create a group and write to it', () => {
4848 assert . equal ( spy . callCount , 2 ) ;
4949 assert . deepEqual ( spy . getCall ( 0 ) . args , [ 500 ] ) ;
5050 assert . deepEqual ( spy . getCall ( 1 ) . args , [ 1000 ] ) ;
51+ assert . equal ( group . getSpeed ( ) , 1000 ) ;
52+ assert . equal ( group . getStreamSpeed ( s1 ) , 500 ) ;
53+ assert . equal ( group . getStreamSpeed ( s2 ) , 500 ) ;
5154 done ( ) ;
5255 } ) ;
5356 } ) ;
@@ -66,6 +69,9 @@ describe('Create a group and write to it', () => {
6669 assert . equal ( group . getStreams ( ) . length , 2 ) ;
6770 s1 . interval ( 100 , 6 , 200 , { end : true } ) ;
6871 s1 . on ( 'end' , ( ) => {
72+ assert . throws ( ( ) => {
73+ group . getStreamSpeed ( s1 ) ;
74+ } , / n o t f o u n d / ) ;
6975 assert . equal ( group . getStreams ( ) . length , 1 ) ;
7076 assert . equal ( group . getSpeed ( ) , 0 ) ;
7177 done ( ) ;
You can’t perform that action at this time.
0 commit comments