rename blob.blob to blob.nativeBlob

also to make the name a bit more unique where we want to do duck typing
This commit is contained in:
Bruno Windels 2020-11-11 10:44:44 +01:00
parent 2cfffa015d
commit c278b0f4a3
2 changed files with 12 additions and 8 deletions

View File

@ -137,9 +137,9 @@ export class Platform {
saveFileAs(blobHandle, filename) { saveFileAs(blobHandle, filename) {
if (navigator.msSaveBlob) { if (navigator.msSaveBlob) {
navigator.msSaveBlob(blobHandle.blob, filename); navigator.msSaveBlob(blobHandle.nativeBlob, filename);
} else { } else {
downloadInIframe(this._container, this._paths.downloadSandbox, blobHandle.blob, filename); downloadInIframe(this._container, this._paths.downloadSandbox, blobHandle.nativeBlob, filename);
} }
} }

View File

@ -71,7 +71,7 @@ const ALLOWED_BLOB_MIMETYPES = {
export class BlobHandle { export class BlobHandle {
constructor(blob, buffer = null) { constructor(blob, buffer = null) {
this.blob = blob; this._blob = blob;
this._buffer = buffer; this._buffer = buffer;
this._url = null; this._url = null;
} }
@ -89,6 +89,10 @@ export class BlobHandle {
return new BlobHandle(file); return new BlobHandle(file);
} }
get nativeBlob() {
return this._blob;
}
async readAsBuffer() { async readAsBuffer() {
if (this._buffer) { if (this._buffer) {
return this._buffer; return this._buffer;
@ -98,7 +102,7 @@ export class BlobHandle {
reader.addEventListener("load", evt => resolve(evt.target.result)); reader.addEventListener("load", evt => resolve(evt.target.result));
reader.addEventListener("error", evt => reject(evt.target.error)); reader.addEventListener("error", evt => reject(evt.target.error));
}); });
reader.readAsArrayBuffer(this.blob); reader.readAsArrayBuffer(this._blob);
return promise; return promise;
} }
} }
@ -112,24 +116,24 @@ export class BlobHandle {
reader.addEventListener("load", evt => resolve(evt.target.result)); reader.addEventListener("load", evt => resolve(evt.target.result));
reader.addEventListener("error", evt => reject(evt.target.error)); reader.addEventListener("error", evt => reject(evt.target.error));
}); });
reader.readAsText(this.blob, "utf-8"); reader.readAsText(this._blob, "utf-8");
return promise; return promise;
} }
} }
get url() { get url() {
if (!this._url) { if (!this._url) {
this._url = URL.createObjectURL(this.blob); this._url = URL.createObjectURL(this._blob);
} }
return this._url; return this._url;
} }
get size() { get size() {
return this.blob.size; return this._blob.size;
} }
get mimeType() { get mimeType() {
return this.blob.type; return this._blob.type;
} }
dispose() { dispose() {