Add function for reading file as array buffer

This commit is contained in:
Dávid Szabó 2016-08-26 01:49:09 +02:00 committed by Julian Descottes
parent 8910bf0dbd
commit fefc635e25

View File

@ -14,6 +14,14 @@
reader.readAsDataURL(file); reader.readAsDataURL(file);
}, },
readFileAsArrayBuffer : function (file, callback) {
var reader = new FileReader();
reader.addEventListener("loadend", function() {
callback(reader.result);
});
reader.readAsArrayBuffer(file);
},
readImageFile : function (file, callback) { readImageFile : function (file, callback) {
ns.FileUtils.readFile(file, function (content) { ns.FileUtils.readFile(file, function (content) {
var image = new Image(); var image = new Image();
@ -28,7 +36,7 @@
saveAs(content, filename); saveAs(content, filename);
} else { } else {
var downloadLink = document.createElement('a'); var downloadLink = document.createElement('a');
content = window.URL.createObjectURL(content); content = window.URL.createObjectURL(new Blob([content]));
downloadLink.setAttribute('href', content); downloadLink.setAttribute('href', content);
downloadLink.setAttribute('download', filename); downloadLink.setAttribute('download', filename);
document.body.appendChild(downloadLink); document.body.appendChild(downloadLink);