From 4bfac53c9a77a3af35d029757eece53f4b7212ed Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Wed, 8 Feb 2012 13:11:48 -0800 Subject: Fixed data type issue on copying library files Fixed the methods to allow for ArrayBuffer data to be sent, fixes saving files that are not plain text. --- js/io/system/chromeapi.js | 2 +- js/io/system/coreioapi.js | 5 +++-- js/io/system/ninjalibrary.js | 18 +++++++++++++++--- 3 files changed, 19 insertions(+), 6 deletions(-) (limited to 'js') diff --git a/js/io/system/chromeapi.js b/js/io/system/chromeapi.js index c19a7d3b..eee7409d 100644 --- a/js/io/system/chromeapi.js +++ b/js/io/system/chromeapi.js @@ -146,7 +146,7 @@ exports.ChromeApi = Montage.create(Object.prototype, { callback({content: this.result, data: file, file: f, url: f.toURL()}); } }; - reader.readAsText(file); + reader.readAsArrayBuffer(file); }, function (e) {if (callback) callback(false)}); }, function (e) {if (callback) callback(false)}); } diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index 7edb469b..e2c2e4dd 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js @@ -402,15 +402,16 @@ exports.CoreIoApi = Montage.create(Component, { xhr = new XMLHttpRequest(); // xhr.open("POST", serviceURL, false); + xhr.responseType = "arraybuffer"; if(file.contentType && file.contentType.length) xhr.setRequestHeader("Content-Type", file.contentType); else xhr.setRequestHeader("Content-Type", "text/plain"); - if(file.contents && file.contents.length) + if (file.contents) xhr.send(file.contents); else - xhr.send(); + xhr.send(); if (xhr.readyState === 4) { retValue.status = xhr.status; diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index 3914ec29..7b524189 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js @@ -114,8 +114,18 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { //File to copy this.chromeApi.fileContent(contents[i].fullPath, function (result) { // - this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content, contentType: result.data.type}); - //this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content}); + + /* +var ui8a = new Uint8Array(result.content); + console.log(ui8a); + + var blob = new window.WebKitBlobBuilder; + blob.append(result.content); +*/ + //console.log(blob.getBlob(result.data.type)); + //this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content, contentType: result.data.type}); + //this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: blob.getBlob(result.data.type), contentType: result.data.type}); + this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content}); }.bind(this)); } } @@ -187,11 +197,12 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { //Getting file contents xhr = new XMLHttpRequest(); xhr.open("GET", tocopylibs[i].path, false); + xhr.responseType = "arraybuffer"; xhr.send(); //Checking for status if (xhr.readyState === 4) { //TODO: add check for mime type //Creating new file from loaded content - //this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, function (status) {if(status) this.libraryCopied()}.bind(this)); + this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, function (status) {if(status) this.libraryCopied()}.bind(this)); } else { //Error creating single file library } @@ -225,6 +236,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { for (i=0; this.files[i]; i++) { xhr = new XMLHttpRequest(); xhr.open("GET", this.root+this.files[i], false); + xhr.responseType = "arraybuffer"; xhr.send(); //Checking for status if (xhr.readyState === 4) { -- cgit v1.2.3