Skip to content

Commit

Permalink
fix(android): fix Ti.Blob.arrayBuffer definition
Browse files Browse the repository at this point in the history
  • Loading branch information
sgtcoolguy committed Jan 13, 2021
1 parent 6f6cea2 commit 2d9bfce
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions common/Resources/ti.internal/extensions/ti/ti.blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,29 @@
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
/* globals OS_IOS, OS_VERSION_MAJOR */
/* globals OS_ANDROID, OS_IOS, OS_VERSION_MAJOR */
const buffer = Ti.createBuffer({ value: '' });
const blob = buffer.toBlob();
const BlobPrototype = Object.getPrototypeOf(blob);
// Web Blob has an arrayBuffer() method that returns a Promise
// https://developer.mozilla.org/en-US/docs/Web/API/Blob/arrayBuffer
BlobPrototype.arrayBuffer = function () {
return new Promise((resolve, reject) => {
let buf;
try {
buf = this.toArrayBuffer();
} catch (err) {
return reject(err);
}
resolve(buf);
if (OS_ANDROID) {
// This doesn't "stick" for iOS. It is implemented natively.
// Web Blob has an arrayBuffer() method that returns a Promise
// https://developer.mozilla.org/en-US/docs/Web/API/Blob/arrayBuffer
Object.defineProperty(BlobPrototype, 'arrayBuffer', {
value: function () {
return new Promise((resolve, reject) => {
let buf;
try {
buf = this.toArrayBuffer();
} catch (err) {
return reject(err);
}
resolve(buf);
});
},
enumerable: true
});
};
}

if (OS_IOS) {
if (OS_VERSION_MAJOR < 13) {
Expand Down

0 comments on commit 2d9bfce

Please sign in to comment.