From c278b0f4a30b5ee7958c9e99e5e5c1516ca8a4ba Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 11 Nov 2020 10:44:44 +0100 Subject: [PATCH] rename blob.blob to blob.nativeBlob also to make the name a bit more unique where we want to do duck typing --- src/platform/web/Platform.js | 4 ++-- src/platform/web/dom/BlobHandle.js | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/platform/web/Platform.js b/src/platform/web/Platform.js index 66373844..6c28e95a 100644 --- a/src/platform/web/Platform.js +++ b/src/platform/web/Platform.js @@ -137,9 +137,9 @@ export class Platform { saveFileAs(blobHandle, filename) { if (navigator.msSaveBlob) { - navigator.msSaveBlob(blobHandle.blob, filename); + navigator.msSaveBlob(blobHandle.nativeBlob, filename); } else { - downloadInIframe(this._container, this._paths.downloadSandbox, blobHandle.blob, filename); + downloadInIframe(this._container, this._paths.downloadSandbox, blobHandle.nativeBlob, filename); } } diff --git a/src/platform/web/dom/BlobHandle.js b/src/platform/web/dom/BlobHandle.js index 2da3a776..00098de1 100644 --- a/src/platform/web/dom/BlobHandle.js +++ b/src/platform/web/dom/BlobHandle.js @@ -71,7 +71,7 @@ const ALLOWED_BLOB_MIMETYPES = { export class BlobHandle { constructor(blob, buffer = null) { - this.blob = blob; + this._blob = blob; this._buffer = buffer; this._url = null; } @@ -89,6 +89,10 @@ export class BlobHandle { return new BlobHandle(file); } + get nativeBlob() { + return this._blob; + } + async readAsBuffer() { if (this._buffer) { return this._buffer; @@ -98,7 +102,7 @@ export class BlobHandle { reader.addEventListener("load", evt => resolve(evt.target.result)); reader.addEventListener("error", evt => reject(evt.target.error)); }); - reader.readAsArrayBuffer(this.blob); + reader.readAsArrayBuffer(this._blob); return promise; } } @@ -112,24 +116,24 @@ export class BlobHandle { reader.addEventListener("load", evt => resolve(evt.target.result)); reader.addEventListener("error", evt => reject(evt.target.error)); }); - reader.readAsText(this.blob, "utf-8"); + reader.readAsText(this._blob, "utf-8"); return promise; } } get url() { if (!this._url) { - this._url = URL.createObjectURL(this.blob); + this._url = URL.createObjectURL(this._blob); } return this._url; } get size() { - return this.blob.size; + return this._blob.size; } get mimeType() { - return this.blob.type; + return this._blob.type; } dispose() {