aboutsummaryrefslogtreecommitdiff
path: root/js/io/system
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-02-08 13:11:48 -0800
committerJose Antonio Marquez2012-02-08 13:11:48 -0800
commit4bfac53c9a77a3af35d029757eece53f4b7212ed (patch)
tree60c9881df445ada5c02ba22e5091b0bab0f92d1b /js/io/system
parent95808eb6ac82b8bf33de658bd135340b66a8fa29 (diff)
downloadninja-4bfac53c9a77a3af35d029757eece53f4b7212ed.tar.gz
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.
Diffstat (limited to 'js/io/system')
-rw-r--r--js/io/system/chromeapi.js2
-rwxr-xr-xjs/io/system/coreioapi.js5
-rw-r--r--js/io/system/ninjalibrary.js18
3 files changed, 19 insertions, 6 deletions
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, {
146 callback({content: this.result, data: file, file: f, url: f.toURL()}); 146 callback({content: this.result, data: file, file: f, url: f.toURL()});
147 } 147 }
148 }; 148 };
149 reader.readAsText(file); 149 reader.readAsArrayBuffer(file);
150 }, function (e) {if (callback) callback(false)}); 150 }, function (e) {if (callback) callback(false)});
151 }, function (e) {if (callback) callback(false)}); 151 }, function (e) {if (callback) callback(false)});
152 } 152 }
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, {
402 xhr = new XMLHttpRequest(); 402 xhr = new XMLHttpRequest();
403 // 403 //
404 xhr.open("POST", serviceURL, false); 404 xhr.open("POST", serviceURL, false);
405 xhr.responseType = "arraybuffer";
405 if(file.contentType && file.contentType.length) 406 if(file.contentType && file.contentType.length)
406 xhr.setRequestHeader("Content-Type", file.contentType); 407 xhr.setRequestHeader("Content-Type", file.contentType);
407 else 408 else
408 xhr.setRequestHeader("Content-Type", "text/plain"); 409 xhr.setRequestHeader("Content-Type", "text/plain");
409 410
410 if(file.contents && file.contents.length) 411 if (file.contents)
411 xhr.send(file.contents); 412 xhr.send(file.contents);
412 else 413 else
413 xhr.send(); 414 xhr.send();
414 415
415 if (xhr.readyState === 4) { 416 if (xhr.readyState === 4) {
416 retValue.status = xhr.status; 417 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, {
114 //File to copy 114 //File to copy
115 this.chromeApi.fileContent(contents[i].fullPath, function (result) { 115 this.chromeApi.fileContent(contents[i].fullPath, function (result) {
116 // 116 //
117 this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content, contentType: result.data.type}); 117
118 //this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content}); 118 /*
119var ui8a = new Uint8Array(result.content);
120 console.log(ui8a);
121
122 var blob = new window.WebKitBlobBuilder;
123 blob.append(result.content);
124*/
125 //console.log(blob.getBlob(result.data.type));
126 //this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content, contentType: result.data.type});
127 //this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: blob.getBlob(result.data.type), contentType: result.data.type});
128 this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content});
119 }.bind(this)); 129 }.bind(this));
120 } 130 }
121 } 131 }
@@ -187,11 +197,12 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
187 //Getting file contents 197 //Getting file contents
188 xhr = new XMLHttpRequest(); 198 xhr = new XMLHttpRequest();
189 xhr.open("GET", tocopylibs[i].path, false); 199 xhr.open("GET", tocopylibs[i].path, false);
200 xhr.responseType = "arraybuffer";
190 xhr.send(); 201 xhr.send();
191 //Checking for status 202 //Checking for status
192 if (xhr.readyState === 4) { //TODO: add check for mime type 203 if (xhr.readyState === 4) { //TODO: add check for mime type
193 //Creating new file from loaded content 204 //Creating new file from loaded content
194 //this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, function (status) {if(status) this.libraryCopied()}.bind(this)); 205 this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, function (status) {if(status) this.libraryCopied()}.bind(this));
195 } else { 206 } else {
196 //Error creating single file library 207 //Error creating single file library
197 } 208 }
@@ -225,6 +236,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
225 for (i=0; this.files[i]; i++) { 236 for (i=0; this.files[i]; i++) {
226 xhr = new XMLHttpRequest(); 237 xhr = new XMLHttpRequest();
227 xhr.open("GET", this.root+this.files[i], false); 238 xhr.open("GET", this.root+this.files[i], false);
239 xhr.responseType = "arraybuffer";
228 xhr.send(); 240 xhr.send();
229 //Checking for status 241 //Checking for status
230 if (xhr.readyState === 4) { 242 if (xhr.readyState === 4) {