@@ -15,20 +15,18 @@ const VCHAR_REGEX = /^[\x21-\x7E]+$/
15
15
16
16
const getOptString = options => options ?. length ? `?${ options . join ( '?' ) } ` : ''
17
17
18
- const _onEnd = Symbol ( '_onEnd' )
19
- const _getOptions = Symbol ( '_getOptions' )
20
- const _emittedSize = Symbol ( '_emittedSize' )
21
- const _emittedIntegrity = Symbol ( '_emittedIntegrity' )
22
- const _emittedVerified = Symbol ( '_emittedVerified' )
23
-
24
18
class IntegrityStream extends MiniPass {
19
+ #emittedIntegrity
20
+ #emittedSize
21
+ #emittedVerified
22
+
25
23
constructor ( opts ) {
26
24
super ( )
27
25
this . size = 0
28
26
this . opts = opts
29
27
30
28
// may be overridden later, but set now for class consistency
31
- this [ _getOptions ] ( )
29
+ this . #getOptions ( )
32
30
33
31
// options used for calculating stream. can't be changed.
34
32
const algorithms = opts ?. algorithms || DEFAULT_ALGORITHMS
@@ -38,7 +36,7 @@ class IntegrityStream extends MiniPass {
38
36
this . hashes = this . algorithms . map ( crypto . createHash )
39
37
}
40
38
41
- [ _getOptions ] ( ) {
39
+ #getOptions ( ) {
42
40
// For verification
43
41
this . sri = this . opts ?. integrity ? parse ( this . opts ?. integrity , this . opts ) : null
44
42
this . expectedSize = this . opts ?. size
@@ -49,24 +47,24 @@ class IntegrityStream extends MiniPass {
49
47
}
50
48
51
49
on ( ev , handler ) {
52
- if ( ev === 'size' && this [ _emittedSize ] ) {
53
- return handler ( this [ _emittedSize ] )
50
+ if ( ev === 'size' && this . #emittedSize ) {
51
+ return handler ( this . #emittedSize )
54
52
}
55
53
56
- if ( ev === 'integrity' && this [ _emittedIntegrity ] ) {
57
- return handler ( this [ _emittedIntegrity ] )
54
+ if ( ev === 'integrity' && this . #emittedIntegrity ) {
55
+ return handler ( this . #emittedIntegrity )
58
56
}
59
57
60
- if ( ev === 'verified' && this [ _emittedVerified ] ) {
61
- return handler ( this [ _emittedVerified ] )
58
+ if ( ev === 'verified' && this . #emittedVerified ) {
59
+ return handler ( this . #emittedVerified )
62
60
}
63
61
64
62
return super . on ( ev , handler )
65
63
}
66
64
67
65
emit ( ev , data ) {
68
66
if ( ev === 'end' ) {
69
- this [ _onEnd ] ( )
67
+ this . #onEnd ( )
70
68
}
71
69
return super . emit ( ev , data )
72
70
}
@@ -77,9 +75,9 @@ class IntegrityStream extends MiniPass {
77
75
return super . write ( data )
78
76
}
79
77
80
- [ _onEnd ] ( ) {
78
+ #onEnd ( ) {
81
79
if ( ! this . goodSri ) {
82
- this [ _getOptions ] ( )
80
+ this . #getOptions ( )
83
81
}
84
82
const newSri = parse ( this . hashes . map ( ( h , i ) => {
85
83
return `${ this . algorithms [ i ] } -${ h . digest ( 'base64' ) } ${ this . optString } `
@@ -104,12 +102,12 @@ class IntegrityStream extends MiniPass {
104
102
err . sri = this . sri
105
103
this . emit ( 'error' , err )
106
104
} else {
107
- this [ _emittedSize ] = this . size
105
+ this . #emittedSize = this . size
108
106
this . emit ( 'size' , this . size )
109
- this [ _emittedIntegrity ] = newSri
107
+ this . #emittedIntegrity = newSri
110
108
this . emit ( 'integrity' , newSri )
111
109
if ( match ) {
112
- this [ _emittedVerified ] = match
110
+ this . #emittedVerified = match
113
111
this . emit ( 'verified' , match )
114
112
}
115
113
}
@@ -423,7 +421,7 @@ function checkData (data, sri, opts) {
423
421
const digest = crypto . createHash ( algorithm ) . update ( data ) . digest ( 'base64' )
424
422
const newSri = parse ( { algorithm, digest } )
425
423
const match = newSri . match ( sri , opts )
426
- opts = opts || Object . create ( null )
424
+ opts = opts || { }
427
425
if ( match || ! ( opts . error ) ) {
428
426
return match
429
427
} else if ( typeof opts . size === 'number' && ( data . length !== opts . size ) ) {
0 commit comments