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