From 116169a4c5a6f42b4840939ebdf0299c6996e580 Mon Sep 17 00:00:00 2001 From: macdonst Date: Sat, 7 May 2011 00:27:07 +0800 Subject: [PATCH] Issue #79: FileWriter.seek() is broken in 0.9.5. The FileEntry.createWriter() method passes in a FileEntry object instead of a File object. As a result the FileWriter.length was not being set properly so when you do a writer.seek(writer.length) it would go to 0, so your next write would overwrite your file. In order to fix this issue the FileEntry.createWriter() method now makes a call to FileEntry.file() to get the correct file size. The File object is now passed to the FileWriter constructor. --- framework/assets/js/file.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/framework/assets/js/file.js b/framework/assets/js/file.js index 73700ee6..1a79f0ea 100755 --- a/framework/assets/js/file.js +++ b/framework/assets/js/file.js @@ -1033,19 +1033,21 @@ FileEntry.prototype.toURI = function(mimeType) { * @param {Function} errorCallback is called with a FileError */ FileEntry.prototype.createWriter = function(successCallback, errorCallback) { - var writer = new FileWriter(this.fullPath); - - if (writer.fileName == null || writer.fileName == "") { - if (typeof errorCallback == "function") { - errorCallback({ - "code": FileError.INVALID_STATE_ERR - }); - } - } - - if (typeof successCallback == "function") { - successCallback(writer); - } + this.file(function(filePointer) { + var writer = new FileWriter(filePointer); + + if (writer.fileName == null || writer.fileName == "") { + if (typeof errorCallback == "function") { + errorCallback({ + "code": FileError.INVALID_STATE_ERR + }); + } + } + + if (typeof successCallback == "function") { + successCallback(writer); + } + }, errorCallback); }; /**