Allow usage of iterable object in Blob constructor. (#108)

* Allow usage of iterable object in Blob constructor.

* Fix ESLint errors
This commit is contained in:
Nick K
2021-07-29 15:42:42 +02:00
committed by GitHub
parent 0b028432d0
commit c2903ca530
2 changed files with 39 additions and 3 deletions
+4 -3
View File
@@ -58,9 +58,10 @@ const _Blob = class Blob {
* @param {{ type?: string }} [options]
*/
constructor(blobParts = [], options = {}) {
const parts = [];
let size = 0;
const parts = blobParts.map(element => {
for (const element of blobParts) {
let part;
if (ArrayBuffer.isView(element)) {
part = new Uint8Array(element.buffer.slice(element.byteOffset, element.byteOffset + element.byteLength));
@@ -73,8 +74,8 @@ const _Blob = class Blob {
}
size += ArrayBuffer.isView(part) ? part.byteLength : part.size;
return part;
});
parts.push(part);
}
const type = options.type === undefined ? '' : String(options.type);