@@ -15,20 +15,6 @@ async function * read(parts) {
15
15
}
16
16
}
17
17
18
- /**
19
- * @template T
20
- * @param {T } object
21
- * @returns {T is Blob }
22
- */
23
- const isBlob = object => {
24
- return (
25
- typeof object === 'object' &&
26
- typeof object . stream === 'function' &&
27
- typeof object . constructor === 'function' &&
28
- / ^ ( B l o b | F i l e ) $ / . test ( object [ Symbol . toStringTag ] )
29
- ) ;
30
- } ;
31
-
32
18
class Blob {
33
19
/**
34
20
* The Blob() constructor returns a new Blob object. The content
@@ -43,13 +29,13 @@ class Blob {
43
29
44
30
const parts = blobParts . map ( element => {
45
31
let buffer ;
46
- if ( Buffer . isBuffer ( element ) ) {
32
+ if ( element instanceof Buffer ) {
47
33
buffer = element ;
48
34
} else if ( ArrayBuffer . isView ( element ) ) {
49
35
buffer = Buffer . from ( element . buffer , element . byteOffset , element . byteLength ) ;
50
36
} else if ( element instanceof ArrayBuffer ) {
51
37
buffer = Buffer . from ( element ) ;
52
- } else if ( isBlob ( element ) ) {
38
+ } else if ( element instanceof Blob ) {
53
39
buffer = element ;
54
40
} else {
55
41
buffer = Buffer . from ( typeof element === 'string' ? element : String ( element ) ) ;
@@ -167,6 +153,20 @@ class Blob {
167
153
168
154
return blob ;
169
155
}
156
+
157
+ get [ Symbol . toStringTag ] ( ) {
158
+ return 'Blob' ;
159
+ }
160
+
161
+ static [ Symbol . hasInstance ] ( object ) {
162
+ return (
163
+ typeof object === 'object' &&
164
+ typeof object . stream === 'function' &&
165
+ object . stream . length === 0 &&
166
+ typeof object . constructor === 'function' &&
167
+ / ^ ( B l o b | F i l e ) $ / . test ( object [ Symbol . toStringTag ] )
168
+ ) ;
169
+ }
170
170
}
171
171
172
172
Object . defineProperties ( Blob . prototype , {
@@ -175,11 +175,4 @@ Object.defineProperties(Blob.prototype, {
175
175
slice : { enumerable : true }
176
176
} ) ;
177
177
178
- Object . defineProperty ( Blob . prototype , Symbol . toStringTag , {
179
- value : 'Blob' ,
180
- writable : false ,
181
- enumerable : false ,
182
- configurable : true
183
- } ) ;
184
-
185
178
module . exports = Blob ;
0 commit comments