aboutsummaryrefslogtreecommitdiff
path: root/js/io/system
diff options
context:
space:
mode:
authorAnanya Sen2012-02-08 15:37:23 -0800
committerAnanya Sen2012-02-08 15:37:23 -0800
commitab6f2f7ada39a9b27408575af9a565daf0a9d291 (patch)
tree92a796e34530d1a724ddb24ef22e59ffef13c12a /js/io/system
parent36b2e540f06cef3887e7d0fea60527fee51e2a40 (diff)
parent5a69d5be181ea98fa842977885ebd8c861dda6ca (diff)
downloadninja-ab6f2f7ada39a9b27408575af9a565daf0a9d291.tar.gz
Merge branch 'FileIO' of github.com:joseeight/ninja-internal into FileIO
Diffstat (limited to 'js/io/system')
-rw-r--r--js/io/system/chromeapi.js408
-rwxr-xr-xjs/io/system/coreioapi.js48
-rw-r--r--js/io/system/ninjalibrary.js287
-rw-r--r--js/io/system/ninjalibrary.json6
4 files changed, 496 insertions, 253 deletions
diff --git a/js/io/system/chromeapi.js b/js/io/system/chromeapi.js
index 6bf6b9fe..eee7409d 100644
--- a/js/io/system/chromeapi.js
+++ b/js/io/system/chromeapi.js
@@ -7,8 +7,10 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
7/* ///////////////////////////////////////////////////////////////////// 7/* /////////////////////////////////////////////////////////////////////
8//////////////////////////////////////////////////////////////////////// 8////////////////////////////////////////////////////////////////////////
9NOTES: 9NOTES:
10
10 The init function starts up the file system API, and a size must be 11 The init function starts up the file system API, and a size must be
11 set, no unlimited available as of now. 12 set, no unlimited available as of now.
13
12//////////////////////////////////////////////////////////////////////// 14////////////////////////////////////////////////////////////////////////
13///////////////////////////////////////////////////////////////////// */ 15///////////////////////////////////////////////////////////////////// */
14// 16//
@@ -31,6 +33,8 @@ exports.ChromeApi = Montage.create(Object.prototype, {
31 var readyEvent = document.createEvent("CustomEvent"); 33 var readyEvent = document.createEvent("CustomEvent");
32 readyEvent.initEvent('ready', true, true); 34 readyEvent.initEvent('ready', true, true);
33 this.dispatchEvent(readyEvent); 35 this.dispatchEvent(readyEvent);
36 //Building data of local Ninja Library
37 this._listNinjaChromeLibrary();
34 }.bind(this), function (e) {return false}); //Returns false on error (not able to init) 38 }.bind(this), function (e) {return false}); //Returns false on error (not able to init)
35 // 39 //
36 return true; 40 return true;
@@ -59,27 +63,160 @@ exports.ChromeApi = Montage.create(Object.prototype, {
59 }, 63 },
60 //////////////////////////////////////////////////////////////////// 64 ////////////////////////////////////////////////////////////////////
61 // 65 //
62 directoryNew: { 66 fileNew: {
67 enumerable: true,
68 value: function(filePath, content, callback) {
69 //
70 this.fileSystem.root.getFile(filePath, {create: true}, function(f) {
71 //
72 f.createWriter(function(writer) {
73 //
74 var mime, blob = new window.WebKitBlobBuilder, type = filePath.split('.');
75 type = type[type.length-1];
76 switch (type) {
77 case 'bmp':
78 mime = 'image/bmp';
79 break;
80 case 'gif':
81 mime = 'image/gif';
82 break;
83 case 'jpeg':
84 mime = 'image/jpeg';
85 break;
86 case 'jpg':
87 mime = 'image/jpeg';
88 break;
89 case 'png':
90 mime = 'image/png';
91 break;
92 case 'rtf':
93 mime = 'application/rtf';
94 break;
95 case 'tif':
96 mime = 'image/tiff';
97 break;
98 case 'tiff':
99 mime = 'image/tiff';
100 break;
101 case 'pdf':
102 mime = 'application/pdf';
103 break;
104 case 'zip':
105 mime = 'application/zip';
106 break;
107 case 'svg':
108 mime = 'image/svg+xml';
109 break;
110 default:
111 mime = 'text/'+type;
112 break;
113 }
114 //
115 blob.append(content);
116 writer.write(blob.getBlob(mime));
117 //
118 if (callback) callback(true);
119 }, function (e) {if (callback) callback(false)});
120 }, function (e) {if (callback) callback(false)});
121 }
122 },
123 ////////////////////////////////////////////////////////////////////
124 //
125 fileDelete: {
126 enumerable: true,
127 value: function(filePath, callback) {
128 this.fileSystem.root.getFile(filePath, {create: false}, function(file) {
129 file.remove(function() {
130 if (callback) callback(true);
131 });
132 }, function (e) {if (callback) callback(false)});
133 }
134 },
135 ////////////////////////////////////////////////////////////////////
136 //
137 fileContent: {
138 enumerable: true,
139 value: function(filePath, callback) {
140 //
141 this.fileSystem.root.getFile(filePath, {}, function(f) {
142 f.file(function(file) {
143 var reader = new FileReader();
144 reader.onloadend = function(e) {
145 if (callback) {
146 callback({content: this.result, data: file, file: f, url: f.toURL()});
147 }
148 };
149 reader.readAsArrayBuffer(file);
150 }, function (e) {if (callback) callback(false)});
151 }, function (e) {if (callback) callback(false)});
152 }
153 },
154 ////////////////////////////////////////////////////////////////////
155 //
156 fileCopy: {
63 enumerable: true, 157 enumerable: true,
64 value: function() { 158 value: function() {
65 } 159 }
66 }, 160 },
67
68 //////////////////////////////////////////////////////////////////// 161 ////////////////////////////////////////////////////////////////////
69 // 162 //
70 directoryDelete: {//TODO: Make sure it uses a force delete 163 fileRename: {
71 enumerable: true, 164 enumerable: true,
72 value: function() { 165 value: function() {
73 } 166 }
74 }, 167 },
75 //////////////////////////////////////////////////////////////////// 168 ////////////////////////////////////////////////////////////////////
76 // 169 //
77 directoryContents: { 170 fileMove: {
78 enumerable: true, 171 enumerable: true,
79 value: function() { 172 value: function() {
80 } 173 }
81 }, 174 },
82 //////////////////////////////////////////////////////////////////// 175 ////////////////////////////////////////////////////////////////////
176 //Creating directory from path, callback optional
177 directoryNew: {
178 enumerable: true,
179 value: function(directoryPath, callback) {
180 //Checking for directory not to already exist
181 this.fileSystem.root.getDirectory(directoryPath, {}, function(dir) {
182 if (callback) callback(false);
183 return; //Directory already exists
184 });
185 //Creating new directory
186 this.fileSystem.root.getDirectory(directoryPath, {create: true}, function(dir) {
187 if (callback) callback(true);
188 }, function (e) {if (callback) callback(false)});
189 }
190 },
191 ////////////////////////////////////////////////////////////////////
192 //
193 directoryDelete: {
194 enumerable: true,
195 value: function(directoryPath, callback) {
196 //
197 this.fileSystem.root.getDirectory(directoryPath, {}, function(dir) {
198 //
199 dir.removeRecursively(function() {
200 if (callback) callback(true);
201 });
202 }, function (e) {if (callback) callback(false)});
203 }
204 },
205 ////////////////////////////////////////////////////////////////////
206 //Returns the directory contents to a callback function
207 directoryContents: {
208 enumerable: true,
209 value: function(directory, callback) {
210 //Creating instance of directory reader
211 this.fileSystem.directoryReader = directory.createReader();
212 //Getting directory contents and sending results to callback
213 this.fileSystem.directoryReader.readEntries(function(results) {
214 //Calling callback with results (null if invalid directory)
215 callback(results);
216 }, function (e) {callback(null)});
217 }
218 },
219 ////////////////////////////////////////////////////////////////////
83 // 220 //
84 directoryCopy: { 221 directoryCopy: {
85 enumerable: true, 222 enumerable: true,
@@ -102,256 +239,31 @@ exports.ChromeApi = Montage.create(Object.prototype, {
102 }, 239 },
103 //////////////////////////////////////////////////////////////////// 240 ////////////////////////////////////////////////////////////////////
104 // 241 //
105 getLocalLibrary: { 242 _listNinjaChromeLibrary: {
106 enumerable: false, 243 enumerable: false,
107 value: function () { 244 value: function () {
245 function parseLibrary (contents) {
246 //
247 var lib = [];
248 //
249 for(var i=0; contents[i]; i++) {