@@ -9,7 +9,7 @@ module.exports = class StreamSpeed extends EventEmitter {
99 *
1010 * @constructor
1111 * @extends {EventEmitter }
12- * @param {Number } per The time unit speed will be measured in.
12+ * @param {number } per The time unit speed will be measured in.
1313 */
1414 constructor ( per ) {
1515 super ( ) ;
@@ -24,8 +24,8 @@ module.exports = class StreamSpeed extends EventEmitter {
2424 * Updates the group with the latest change in speed.
2525 *
2626 * @param {Object } meta
27- * @param {Number } speed
28- * @param {Number } avg
27+ * @param {number } speed
28+ * @param {number } avg
2929 */
3030 _update ( meta , speed , avg ) {
3131 meta . speed = speed ;
@@ -62,38 +62,38 @@ module.exports = class StreamSpeed extends EventEmitter {
6262 /**
6363 * Add stream to group.
6464 *
65- * @param {Stream } stream
65+ * @param {Readable } stream
6666 */
6767 add ( origstream ) {
6868 // Check if stream is already in group.
6969 if ( this . _streams . some ( m => m . stream === origstream ) ) {
7070 throw Error ( 'Stream already in group' ) ;
7171 }
72-
73- var onReadable = ( ) => {
74- var data = stream . read ( ) ;
72+
73+ const onReadable = ( ) => {
74+ const data = stream . read ( ) ;
7575 if ( data ) {
7676 reader . update ( data , onUpdate ) ;
7777 }
7878 } ;
7979
80- var cleanup = ( ) => {
80+ const cleanup = ( ) => {
8181 stream . removeListener ( 'readable' , onReadable ) ;
8282 stream . removeListener ( 'end' , cleanup ) ;
8383 origstream . removeListener ( 'error' , cleanup ) ;
8484 this . _streams . splice ( this . _streams . indexOf ( meta ) , 1 ) ;
8585 } ;
8686
87- var meta = {
87+ const meta = {
8888 stream : origstream ,
8989 speed : 0 ,
9090 avg : 0 ,
9191 cleanup,
9292 } ;
9393 this . _streams . push ( meta ) ;
94- var reader = new Speedometer ( this . per ) ;
95- var stream = origstream . pipe ( new PassThrough ( ) ) ;
96- var onUpdate = this . _update . bind ( this , meta ) ;
94+ const reader = new Speedometer ( this . per ) ;
95+ const stream = origstream . pipe ( new PassThrough ( ) ) ;
96+ const onUpdate = this . _update . bind ( this , meta ) ;
9797
9898 stream . on ( 'readable' , onReadable ) ;
9999 stream . on ( 'end' , cleanup ) ;
@@ -108,14 +108,10 @@ module.exports = class StreamSpeed extends EventEmitter {
108108 */
109109 remove ( stream ) {
110110 // Check if stream is in group.
111- var meta ;
112- if ( ! this . _streams . some ( function ( m ) {
113- meta = m ;
114- return m . stream === stream ;
115- } ) ) {
111+ const meta = this . _streams . find ( m => m . stream === stream ) ;
112+ if ( ! meta ) {
116113 throw Error ( 'Stream not found in group' ) ;
117114 }
118-
119115 meta . cleanup ( ) ;
120116 }
121117
@@ -124,14 +120,14 @@ module.exports = class StreamSpeed extends EventEmitter {
124120 * Converts bytes to human readable unit.
125121 * Thank you Amir from StackOverflow.
126122 *
127- * @param {Number } bytes
128- * @return {String }
123+ * @param {number } bytes
124+ * @return {string }
129125 */
130126 static toHuman ( bytes , timeUnit ) {
131- var units = ' KMGTPEZYXWVU' ;
127+ const units = ' KMGTPEZYXWVU' ;
132128 if ( bytes <= 0 ) { return '0' ; }
133129 timeUnit = timeUnit ? '/' + timeUnit : '' ;
134- var t2 = Math . min ( Math . floor ( Math . log ( bytes ) / Math . log ( 1024 ) ) , 12 ) ;
130+ const t2 = Math . min ( Math . floor ( Math . log ( bytes ) / Math . log ( 1024 ) ) , 12 ) ;
135131 return ( Math . round ( bytes * 100 / Math . pow ( 1024 , t2 ) ) / 100 ) +
136132 units . charAt ( t2 ) . replace ( ' ' , '' ) + 'B' + timeUnit ;
137133 }
0 commit comments