Skip to content

Commit 6134add

Browse files
author
David Frank
committed
test blob
1 parent 544a1d3 commit 6134add

File tree

4 files changed

+4767
-13
lines changed

4 files changed

+4767
-13
lines changed

blob.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
// 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
23
// (MIT licensed)
34

4-
import Stream from 'stream';
5-
6-
// fix for "Readable" isn't a named export issue
5+
const Stream = require('stream');
76
const Readable = Stream.Readable;
87

9-
export const BUFFER = Symbol('buffer');
8+
const BUFFER = Symbol('buffer');
109
const TYPE = Symbol('type');
1110

12-
export default class Blob {
11+
class Blob {
1312
constructor() {
1413
this[TYPE] = '';
1514

@@ -43,7 +42,9 @@ export default class Blob {
4342

4443
this[BUFFER] = Buffer.concat(buffers);
4544

46-
let type = options && options.type !== undefined && String(options.type).toLowerCase();
45+
let type = options &&
46+
options.type !== undefined &&
47+
String(options.type).toLowerCase();
4748
if (type && !/[^\u0020-\u007E]/.test(type)) {
4849
this[TYPE] = type;
4950
}
@@ -63,11 +64,11 @@ export default class Blob {
6364
return Promise.resolve(ab);
6465
}
6566
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;
7172
}
7273
toString() {
7374
return '[object Blob]'
@@ -117,3 +118,5 @@ Object.defineProperty(Blob.prototype, Symbol.toStringTag, {
117118
enumerable: false,
118119
configurable: true
119120
});
121+
122+
module.exports = Blob;

0 commit comments

Comments
 (0)