Return-Path: X-Original-To: apmail-incubator-callback-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-callback-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DD81A9A41 for ; Thu, 17 May 2012 22:37:08 +0000 (UTC) Received: (qmail 55675 invoked by uid 500); 17 May 2012 22:37:08 -0000 Delivered-To: apmail-incubator-callback-commits-archive@incubator.apache.org Received: (qmail 55651 invoked by uid 500); 17 May 2012 22:37:08 -0000 Mailing-List: contact callback-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@incubator.apache.org Delivered-To: mailing list callback-commits@incubator.apache.org Received: (qmail 55577 invoked by uid 99); 17 May 2012 22:37:08 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 May 2012 22:37:08 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 5960216805; Thu, 17 May 2012 22:37:08 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: timkim@apache.org To: callback-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [11/19] js commit: seek can now append stuff to files Message-Id: <20120517223708.5960216805@tyr.zones.apache.org> Date: Thu, 17 May 2012 22:37:08 +0000 (UTC) seek can now append stuff to files Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/6c34ea6b Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/6c34ea6b Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/6c34ea6b Branch: refs/heads/playbookFile Commit: 6c34ea6b80b270b5d26e04b46858c2a7798754f6 Parents: 487f5ee Author: Tim Kim Authored: Wed May 9 16:38:00 2012 -0700 Committer: Tim Kim Committed: Wed May 9 16:38:00 2012 -0700 ---------------------------------------------------------------------- lib/playbook/plugin/playbook/FileWriter.js | 45 ++++++++++++++++------- 1 files changed, 31 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/6c34ea6b/lib/playbook/plugin/playbook/FileWriter.js ---------------------------------------------------------------------- diff --git a/lib/playbook/plugin/playbook/FileWriter.js b/lib/playbook/plugin/playbook/FileWriter.js index 91ef97f..f2dfced 100644 --- a/lib/playbook/plugin/playbook/FileWriter.js +++ b/lib/playbook/plugin/playbook/FileWriter.js @@ -88,45 +88,62 @@ FileWriter.prototype.write = function(text) { // can't append to file - must open a temp file, write to temp, then delete current file // and save again - lame // also have to investigate how bb blobs work in order to set proper seek positions :S - console.log('writing to file'); - + if (typeof me.onwrite === "function") { - me.onwrite(new ProgressEvent("write", {"target":me})); + me.onwrite(new ProgressEvent("write", {"target":me})); } - + var textBlob = blackberry.utils.stringToBlob(text); + if(blackberry.io.file.exists(this.fileName)){ - // for now just overwrite - var oldTextBlob = ''; - + + var oldText = ''; + var newText = text; + var getFileContents = function(path,blob){ if(blob){ - oldTextBlob = blackberry.utils.blobToString(blob); + oldText = blackberry.utils.blobToString(blob); + if(oldText.length>0){ + console.log('old text: ' + oldText); + newText = oldText.substr(0,me.position) + text + oldText.substr(me.position); + console.log('newText: '+ newText); + } } - // seek position stuff here - var newTextBlob = text; var tempFile = me.fileName+'temp'; if(blackberry.io.file.exists(tempFile)){ blackberry.io.file.deleteFile(tempFile); } - - // crete a temp file, delete file we are 'overwriting', then rename temp file - blackberry.io.file.saveFile(tempFile, blackberry.utils.stringToBlob(newTextBlob)); + + var newTextBlob = blackberry.utils.stringToBlob(newText); + + // crete a temp file, delete file we are 'overwriting', then rename temp file + blackberry.io.file.saveFile(tempFile, newTextBlob); blackberry.io.file.deleteFile(me.fileName); blackberry.io.file.rename(tempFile, me.fileName.split('/').pop()); + + me.position = newText.length; + me.length = me.position; } // setting asynch to off - worry about making this all callbacks later blackberry.io.file.readFile(this.fileName, getFileContents, false); }else{ + + // file is new so just save it blackberry.io.file.saveFile(this.fileName, textBlob); + me.position = text.length; + me.length = me.position; } me.readyState = FileWriter.DONE; - console.log('done writing file'); + + if (typeof me.onwriteend === "function") { + me.onwriteend(new ProgressEvent("writeend", {"target":me})); + } + /* exec( // Success callback