@@ -30,6 +30,10 @@ const getOptString = options => !options || !options.length
3030
3131const _onEnd = Symbol ( '_onEnd' )
3232const _getOptions = Symbol ( '_getOptions' )
33+ const _emittedSize = Symbol ( '_emittedSize' )
34+ const _emittedIntegrity = Symbol ( '_emittedIntegrity' )
35+ const _emittedVerified = Symbol ( '_emittedVerified' )
36+
3337class IntegrityStream extends MiniPass {
3438 constructor ( opts ) {
3539 super ( )
@@ -63,6 +67,22 @@ class IntegrityStream extends MiniPass {
6367 this . optString = getOptString ( options )
6468 }
6569
70+ on ( ev , handler ) {
71+ if ( ev === 'size' && this [ _emittedSize ] ) {
72+ return handler ( this [ _emittedSize ] )
73+ }
74+
75+ if ( ev === 'integrity' && this [ _emittedIntegrity ] ) {
76+ return handler ( this [ _emittedIntegrity ] )
77+ }
78+
79+ if ( ev === 'verified' && this [ _emittedVerified ] ) {
80+ return handler ( this [ _emittedVerified ] )
81+ }
82+
83+ return super . on ( ev , handler )
84+ }
85+
6686 emit ( ev , data ) {
6787 if ( ev === 'end' ) {
6888 this [ _onEnd ] ( )
@@ -103,9 +123,14 @@ class IntegrityStream extends MiniPass {
103123 err . sri = this . sri
104124 this . emit ( 'error' , err )
105125 } else {
126+ this [ _emittedSize ] = this . size
106127 this . emit ( 'size' , this . size )
128+ this [ _emittedIntegrity ] = newSri
107129 this . emit ( 'integrity' , newSri )
108- match && this . emit ( 'verified' , match )
130+ if ( match ) {
131+ this [ _emittedVerified ] = match
132+ this . emit ( 'verified' , match )
133+ }
109134 }
110135 }
111136}
0 commit comments