1
1
// Based on https://github.com/tmpvar/jsdom/blob/aa85b2abf07766ff7bf5c1f6daafb3726f2f2db5/lib/jsdom/living/blob.js
2
+ // Also based on https://github.com/bitinn/node-fetch/blob/v2.5.0/src/blob.js
2
3
// (MIT licensed)
3
4
4
- import Stream from 'stream' ;
5
-
6
- // fix for "Readable" isn't a named export issue
5
+ const Stream = require ( 'stream' ) ;
7
6
const Readable = Stream . Readable ;
8
7
9
- export const BUFFER = Symbol ( 'buffer' ) ;
8
+ const BUFFER = Symbol ( 'buffer' ) ;
10
9
const TYPE = Symbol ( 'type' ) ;
11
10
12
- export default class Blob {
11
+ class Blob {
13
12
constructor ( ) {
14
13
this [ TYPE ] = '' ;
15
14
@@ -43,7 +42,9 @@ export default class Blob {
43
42
44
43
this [ BUFFER ] = Buffer . concat ( buffers ) ;
45
44
46
- let type = options && options . type !== undefined && String ( options . type ) . toLowerCase ( ) ;
45
+ let type = options &&
46
+ options . type !== undefined &&
47
+ String ( options . type ) . toLowerCase ( ) ;
47
48
if ( type && ! / [ ^ \u0020 - \u007E ] / . test ( type ) ) {
48
49
this [ TYPE ] = type ;
49
50
}
@@ -63,11 +64,11 @@ export default class Blob {
63
64
return Promise . resolve ( ab ) ;
64
65
}
65
66
stream ( ) {
66
- const readable = new Readable ( ) ;
67
- readable . _read = ( ) => { } ;
68
- readable . push ( this [ BUFFER ] ) ;
69
- readable . push ( null ) ;
70
- return readable ;
67
+ const readable = new Readable ( ) ;
68
+ readable . _read = ( ) => { } ;
69
+ readable . push ( this [ BUFFER ] ) ;
70
+ readable . push ( null ) ;
71
+ return readable ;
71
72
}
72
73
toString ( ) {
73
74
return '[object Blob]'
@@ -117,3 +118,5 @@ Object.defineProperty(Blob.prototype, Symbol.toStringTag, {
117
118
enumerable : false ,
118
119
configurable : true
119
120
} ) ;
121
+
122
+ module . exports = Blob ;
0 commit comments