@@ -50,7 +50,6 @@ const {
50
50
51
51
const {
52
52
validateObject,
53
- validateString,
54
53
isUint32,
55
54
} = require ( 'internal/validators' ) ;
56
55
@@ -76,22 +75,10 @@ function getSource(source, encoding) {
76
75
if ( isBlob ( source ) )
77
76
return [ source . size , source [ kHandle ] ] ;
78
77
79
- if ( typeof source === 'string' ) {
80
- source = lazyBuffer ( ) . from ( source , encoding ) ;
81
- } else if ( isAnyArrayBuffer ( source ) ) {
78
+ if ( isAnyArrayBuffer ( source ) ) {
82
79
source = new Uint8Array ( source ) ;
83
80
} else if ( ! isArrayBufferView ( source ) ) {
84
- throw new ERR_INVALID_ARG_TYPE (
85
- 'source' ,
86
- [
87
- 'string' ,
88
- 'ArrayBuffer' ,
89
- 'SharedArrayBuffer' ,
90
- 'Buffer' ,
91
- 'TypedArray' ,
92
- 'DataView'
93
- ] ,
94
- source ) ;
81
+ source = lazyBuffer ( ) . from ( `${ source } ` , encoding ) ;
95
82
}
96
83
97
84
// We copy into a new Uint8Array because the underlying
@@ -112,19 +99,16 @@ class InternalBlob extends JSTransferable {
112
99
}
113
100
114
101
class Blob extends JSTransferable {
115
- constructor ( sources = [ ] , options ) {
102
+ constructor ( sources = [ ] , options = { } ) {
116
103
emitExperimentalWarning ( 'buffer.Blob' ) ;
117
104
if ( sources === null ||
118
105
typeof sources [ SymbolIterator ] !== 'function' ||
119
106
typeof sources === 'string' ) {
120
107
throw new ERR_INVALID_ARG_TYPE ( 'sources' , 'Iterable' , sources ) ;
121
108
}
122
- if ( options !== undefined )
123
- validateObject ( options , 'options' ) ;
124
- const {
125
- encoding = 'utf8' ,
126
- type = '' ,
127
- } = { ...options } ;
109
+ validateObject ( options , 'options' ) ;
110
+ const { encoding = 'utf8' } = options ;
111
+ let { type = '' } = options ;
128
112
129
113
let length = 0 ;
130
114
const sources_ = ArrayFrom ( sources , ( source ) => {
@@ -133,16 +117,14 @@ class Blob extends JSTransferable {
133
117
return src ;
134
118
} ) ;
135
119
136
- // This is a MIME media type but we're not actively checking the syntax.
137
- // But, to be fair, neither does Chrome.
138
- validateString ( type , 'options.type' ) ;
139
-
140
120
if ( ! isUint32 ( length ) )
141
121
throw new ERR_BUFFER_TOO_LARGE ( 0xFFFFFFFF ) ;
142
122
143
123
super ( ) ;
144
124
this [ kHandle ] = createBlob ( sources_ , length ) ;
145
125
this [ kLength ] = length ;
126
+
127
+ type = `${ type } ` ;
146
128
this [ kType ] = RegExpPrototypeTest ( disallowedTypeCharacters , type ) ?
147
129
'' : StringPrototypeToLowerCase ( type ) ;
148
130
}
0 commit comments