| Left: | ||
| Right: |
| 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 }, callback); | 169 }, callback); |
| 170 }, callback); | 170 }, callback); |
| 171 }, | 171 }, |
| 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 var executeWriteOperation = function(op, nextOperation) |
| 180 { | 180 { |
| 181 if (writer.error) | 181 writer.onwriteend = function() |
| 182 callback(writer.error); | 182 { |
| 183 else | 183 if (writer.error) |
| 184 callback(null); | 184 callback(writer.error); |
| 185 }; | 185 else |
| 186 nextOperation(); | |
| 187 }.bind(this); | |
|
Felix Dahlke
2012/10/12 08:16:21
Why bind this? Doesn't seem to be used.
| |
| 186 | 188 |
| 187 var blob; | 189 op(); |
| 188 try | 190 }.bind(this); |
|
Felix Dahlke
2012/10/12 08:16:21
Again, why bind this?
| |
| 191 | |
| 192 executeWriteOperation(writer.truncate.bind(writer, 0), function() | |
| 189 { | 193 { |
| 190 blob = new Blob([data.join("\n") + "\n"], {type: "text/plain"}); | 194 var blob; |
| 191 } | 195 try |
| 192 catch (e) | 196 { |
| 193 { | 197 blob = new Blob([data.join(this.lineBreak) + this.lineBreak], {typ e: "text/plain"}); |
| 194 if (!(e instanceof TypeError)) | 198 } |
| 195 throw e; | 199 catch (e) |
| 200 { | |
| 201 if (!(e instanceof TypeError)) | |
| 202 throw e; | |
| 196 | 203 |
| 197 // Blob wasn't a constructor before Chrome 20 | 204 // Blob wasn't a constructor before Chrome 20 |
| 198 var builder = new (window.BlobBuilder || window.WebKitBlobBuilder); | 205 var builder = new (window.BlobBuilder || window.WebKitBlobBuilder) ; |
| 199 builder.append(data.join("\n") + "\n"); | 206 builder.append(data.join(this.lineBreak) + this.lineBreak); |
| 200 blob = builder.getBlob("text/plain"); | 207 blob = builder.getBlob("text/plain"); |
| 201 } | 208 } |
| 202 writer.write(blob); | 209 executeWriteOperation(writer.write.bind(writer, blob), callback.bind (null, null)); |
| 203 }, callback); | 210 }.bind(this)); |
| 204 }, callback); | 211 }.bind(this), callback); |
| 212 }.bind(this), callback); | |
| 205 }, | 213 }, |
| 206 | 214 |
| 207 copyFile: function(fromFile, toFile, callback) | 215 copyFile: function(fromFile, toFile, callback) |
| 208 { | 216 { |
| 209 // Simply combine read and write operations | 217 // Simply combine read and write operations |
| 210 var data = []; | 218 var data = []; |
| 211 this.readFromFile(fromFile, false, { | 219 this.readFromFile(fromFile, false, { |
| 212 process: function(line) | 220 process: function(line) |
| 213 { | 221 { |
| 214 if (line !== null) | 222 if (line !== null) |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 531 status: -1, | 539 status: -1, |
| 532 notificationCallbacks: {}, | 540 notificationCallbacks: {}, |
| 533 loadFlags: 0, | 541 loadFlags: 0, |
| 534 INHIBIT_CACHING: 0, | 542 INHIBIT_CACHING: 0, |
| 535 VALIDATE_ALWAYS: 0, | 543 VALIDATE_ALWAYS: 0, |
| 536 QueryInterface: function() | 544 QueryInterface: function() |
| 537 { | 545 { |
| 538 return this; | 546 return this; |
| 539 } | 547 } |
| 540 }; | 548 }; |
| OLD | NEW |