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