| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 if (fileSize === -1) | 456 if (fileSize === -1) |
| 457 return; | 457 return; |
| 458 if (chunk) { | 458 if (chunk) { |
| 459 chunk.startOffset = this._fileSize; | 459 chunk.startOffset = this._fileSize; |
| 460 chunk.endOffset = fileSize; | 460 chunk.endOffset = fileSize; |
| 461 chunk.string = null; | 461 chunk.string = null; |
| 462 } | 462 } |
| 463 this._fileSize = fileSize; | 463 this._fileSize = fileSize; |
| 464 } | 464 } |
| 465 | 465 |
| 466 if (!this._file) |
| 467 this._file = new Bindings.DeferredTempFile(this._dirName, String(Date.now(
))); |
| 466 this._file.write(this._strings, didWrite.bind(this, chunk)); | 468 this._file.write(this._strings, didWrite.bind(this, chunk)); |
| 467 this._strings = []; | 469 this._strings = []; |
| 468 this._stringsLength = 0; | 470 this._stringsLength = 0; |
| 469 return chunk; | 471 return chunk; |
| 470 } | 472 } |
| 471 | 473 |
| 472 /** | 474 /** |
| 473 * @override | 475 * @override |
| 474 */ | 476 */ |
| 475 finishWriting() { | 477 finishWriting() { |
| 476 this._flush(false); | 478 this._flush(false); |
| 477 this._file.finishWriting(function() {}); | 479 this._file.finishWriting(function() {}); |
| 478 } | 480 } |
| 479 | 481 |
| 480 /** | 482 /** |
| 481 * @override | 483 * @override |
| 482 */ | 484 */ |
| 483 reset() { | 485 reset() { |
| 484 if (this._file) | 486 if (this._file) |
| 485 this._file.remove(); | 487 this._file.remove(); |
| 486 this._file = new Bindings.DeferredTempFile(this._dirName, String(Date.now())
); | 488 this._file = null; |
| 487 /** | 489 /** |
| 488 * @type {!Array.<string>} | 490 * @type {!Array.<string>} |
| 489 */ | 491 */ |
| 490 this._strings = []; | 492 this._strings = []; |
| 491 this._stringsLength = 0; | 493 this._stringsLength = 0; |
| 492 this._fileSize = 0; | 494 this._fileSize = 0; |
| 493 } | 495 } |
| 494 | 496 |
| 495 /** | 497 /** |
| 496 * @param {!Common.OutputStream} outputStream | 498 * @param {!Common.OutputStream} outputStream |
| 497 * @param {!Bindings.OutputStreamDelegate} delegate | 499 * @param {!Bindings.OutputStreamDelegate} delegate |
| 498 */ | 500 */ |
| 499 writeToStream(outputStream, delegate) { | 501 writeToStream(outputStream, delegate) { |
| 500 this._file.copyToOutputStream(outputStream, delegate); | 502 if (this._file) |
| 503 this._file.copyToOutputStream(outputStream, delegate); |
| 501 } | 504 } |
| 502 }; | 505 }; |
| 503 | 506 |
| 504 /** | 507 /** |
| 505 * @typedef {{ | 508 * @typedef {{ |
| 506 * string: ?string, | 509 * string: ?string, |
| 507 * startOffset: number, | 510 * startOffset: number, |
| 508 * endOffset: number | 511 * endOffset: number |
| 509 * }} | 512 * }} |
| 510 */ | 513 */ |
| 511 Bindings.TempFileBackingStorage.Chunk; | 514 Bindings.TempFileBackingStorage.Chunk; |
| OLD | NEW |