Merge pull request #1545 from dpalou/MOBILE-2642

MOBILE-2642 desktop: Fix write file in chunks
This commit is contained in:
Juan Leyva 2018-10-03 12:05:02 +02:00 committed by GitHub
commit bd066eee47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -592,13 +592,22 @@ export class FileWriterMock {
* @param {Buffer} data The data to write. * @param {Buffer} data The data to write.
*/ */
protected writeFile(data: Buffer): void { protected writeFile(data: Buffer): void {
this.fs.writeFile(this.localURL, data, (err) => { /* Create a write stream so we can specify where to start writing. Node's Writable stream doesn't allow specifying the
if (err) { position once it's been created, that's why we need to create it everytime write is called. */
this.onerror && this.onerror(err); const stream = this.fs.createWriteStream(this.localURL, {flags: 'r+', start: this.position});
} else {
this.onwrite && this.onwrite(); stream.on('error', (err) => {
} this.onerror && this.onerror(err);
});
stream.end(data, () => {
// Update the position.
this.position += data.length;
this.onwrite && this.onwrite();
this.onwriteend && this.onwriteend(); this.onwriteend && this.onwriteend();
stream.destroy();
}); });
this.onwritestart && this.onwritestart(); this.onwritestart && this.onwritestart();