OLD | NEW |
1 /* | 1 /* |
2 * This Source Code is subject to the terms of the Mozilla Public License | 2 * This Source Code is subject to the terms of the Mozilla Public License |
3 * version 2.0 (the "License"). You can obtain a copy of the License at | 3 * version 2.0 (the "License"). You can obtain a copy of the License at |
4 * http://mozilla.org/MPL/2.0/. | 4 * http://mozilla.org/MPL/2.0/. |
5 */ | 5 */ |
6 | 6 |
7 // | 7 // |
8 // Module framework stuff | 8 // Module framework stuff |
9 // | 9 // |
10 | 10 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 | 172 |
173 writeToFile: function(file, encode, data, callback, timeLineID) | 173 writeToFile: function(file, encode, data, callback, timeLineID) |
174 { | 174 { |
175 this._getFileEntry(file, true, function(fs, fileEntry) | 175 this._getFileEntry(file, true, function(fs, fileEntry) |
176 { | 176 { |
177 fileEntry.createWriter(function(writer) | 177 fileEntry.createWriter(function(writer) |
178 { | 178 { |
179 writer.onwriteend = function() | 179 writer.onwriteend = function() |
180 { | 180 { |
181 if (writer.error) | 181 if (writer.error) |
| 182 { |
182 callback(writer.error); | 183 callback(writer.error); |
183 else | 184 return; |
184 callback(null); | 185 } |
185 }; | |
186 | 186 |
187 var blob; | 187 writer.onwriteend = function() |
188 try | 188 { |
189 { | 189 if (writer.error) |
190 blob = new Blob([data.join("\n") + "\n"], {type: "text/plain"}); | 190 callback(writer.error); |
191 } | 191 else |
192 catch (e) | 192 callback(null); |
193 { | 193 }.bind(this); |
194 if (!(e instanceof TypeError)) | |
195 throw e; | |
196 | 194 |
197 // Blob wasn't a constructor before Chrome 20 | 195 var blob; |
198 var builder = new (window.BlobBuilder || window.WebKitBlobBuilder); | 196 try |
199 builder.append(data.join("\n") + "\n"); | 197 { |
200 blob = builder.getBlob("text/plain"); | 198 blob = new Blob([data.join(this.lineBreak) + this.lineBreak], {typ
e: "text/plain"}); |
201 } | 199 } |
202 writer.write(blob); | 200 catch (e) |
203 }, callback); | 201 { |
204 }, callback); | 202 if (!(e instanceof TypeError)) |
| 203 throw e; |
| 204 |
| 205 // Blob wasn't a constructor before Chrome 20 |
| 206 var builder = new (window.BlobBuilder || window.WebKitBlobBuilder)
; |
| 207 builder.append(data.join(this.lineBreak) + this.lineBreak); |
| 208 blob = builder.getBlob("text/plain"); |
| 209 } |
| 210 writer.write(blob); |
| 211 }.bind(this); |
| 212 writer.truncate(0); |
| 213 }.bind(this), callback); |
| 214 }.bind(this), callback); |
205 }, | 215 }, |
206 | 216 |
207 copyFile: function(fromFile, toFile, callback) | 217 copyFile: function(fromFile, toFile, callback) |
208 { | 218 { |
209 // Simply combine read and write operations | 219 // Simply combine read and write operations |
210 var data = []; | 220 var data = []; |
211 this.readFromFile(fromFile, false, { | 221 this.readFromFile(fromFile, false, { |
212 process: function(line) | 222 process: function(line) |
213 { | 223 { |
214 if (line !== null) | 224 if (line !== null) |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 status: -1, | 541 status: -1, |
532 notificationCallbacks: {}, | 542 notificationCallbacks: {}, |
533 loadFlags: 0, | 543 loadFlags: 0, |
534 INHIBIT_CACHING: 0, | 544 INHIBIT_CACHING: 0, |
535 VALIDATE_ALWAYS: 0, | 545 VALIDATE_ALWAYS: 0, |
536 QueryInterface: function() | 546 QueryInterface: function() |
537 { | 547 { |
538 return this; | 548 return this; |
539 } | 549 } |
540 }; | 550 }; |
OLD | NEW |