Commit e7a83798 authored by Romain Courteaud's avatar Romain Courteaud

Move blob reader promises

parent 7afa86e8
/*global window, RSVP, Blob, XMLHttpRequest, QueryFactory, Query, console */
/*jslint maxlen: 200*/ /*jslint maxlen: 200*/
(function (window, RSVP, Blob, QueryFactory, Query) { /*global window, RSVP, Blob, XMLHttpRequest, QueryFactory, Query, console, FileReader */
(function (window, RSVP, Blob, QueryFactory, Query, FileReader) {
"use strict"; "use strict";
var util = {}, var util = {},
...@@ -152,6 +152,32 @@ ...@@ -152,6 +152,32 @@
function readBlobAsText(blob) {
var fr = new FileReader();
return new RSVP.Promise(function (resolve, reject, notify) {
fr.addEventListener("load", resolve);
fr.addEventListener("error", reject);
fr.addEventListener("progress", notify);
fr.readAsText(blob);
}, function () {
fr.abort();
});
}
util.readBlobAsText = readBlobAsText;
function readBlobAsArrayBuffer(blob) {
var fr = new FileReader();
return new RSVP.Promise(function (resolve, reject, notify) {
fr.addEventListener("load", resolve);
fr.addEventListener("error", reject);
fr.addEventListener("progress", notify);
fr.readAsArrayBuffer(blob);
}, function () {
fr.abort();
});
}
util.readBlobAsArrayBuffer = readBlobAsArrayBuffer;
...@@ -429,4 +455,4 @@ ...@@ -429,4 +455,4 @@
jIO = new JioBuilder(); jIO = new JioBuilder();
window.jIO = jIO; window.jIO = jIO;
}(window, RSVP, Blob, QueryFactory, Query)); }(window, RSVP, Blob, QueryFactory, Query, FileReader));
...@@ -245,33 +245,6 @@ function readBlobAsBinaryString(blob) { ...@@ -245,33 +245,6 @@ function readBlobAsBinaryString(blob) {
} }
exports.util.readBlobAsBinaryString = readBlobAsBinaryString; exports.util.readBlobAsBinaryString = readBlobAsBinaryString;
function readBlobAsArrayBuffer(blob) {
var fr = new FileReader();
return new RSVP.Promise(function (resolve, reject, notify) {
fr.addEventListener("load", resolve);
fr.addEventListener("error", reject);
fr.addEventListener("progress", notify);
fr.readAsArrayBuffer(blob);
}, function () {
fr.abort();
});
}
exports.util.readBlobAsArrayBuffer = readBlobAsArrayBuffer;
function readBlobAsText(blob) {
var fr = new FileReader();
return new RSVP.Promise(function (resolve, reject, notify) {
fr.addEventListener("load", resolve);
fr.addEventListener("error", reject);
fr.addEventListener("progress", notify);
fr.readAsText(blob);
}, function () {
fr.abort();
});
}
exports.util.readBlobAsText = readBlobAsText;
/** /**
* Acts like `Array.prototype.concat` but does not create a copy of the original * Acts like `Array.prototype.concat` but does not create a copy of the original
* array. It extends the original array and return it. * array. It extends the original array and return it.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment