incubator-callback-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Simon MacDonald (Created) (JIRA)" <>
Subject [jira] [Created] (CB-472) does not actually seek to the beginning of the file.
Date Tue, 10 Apr 2012 13:19:16 GMT does not actually seek to the beginning of the file.

                 Key: CB-472
             Project: Apache Callback
          Issue Type: Bug
          Components: CordovaJS
    Affects Versions: 1.5.0, 1.4.0, 1.3.0, 1.2.0, 1.1.0, 1.0.0
            Reporter: Simon MacDonald
            Assignee: Simon MacDonald

Tom Jenkins via 

Hi all,
Not sure I'm going about this the right way, and sorry if it's been covered (I did do a prior
search), but anyway. I'm writing to a csv file using phonegap, to record 'hits' on different
parts of an app. Let's say the columns are something like Section level 1, Section  level
2, Page, Num. views.

Obviously I need to read in the file each time (I suppose I could store the data in a JS array
and write periodically, but anyway) to check whether the'hit' that has just occurred needs
to increment the view count on an existing row, or add a new row (i.e. has the section been
visited before or not). This is all fine, dandy and working. I then need to calculate the
new contents of the file and write it back. It's simplest to just overwrite the entire contents,
so I try:;

What actually happens is the data gets appended instead. I found this is because when I call, it's not actually seeking, because of this check in

if (!offset) {

I assume that the check is to catch offset values that are for some reason null or false (unchecked
return of a function call or something). However, this obviously means that seek(0) will never
seek, because the check sees the 0 as boolean false. To get my code to work, I've simply changed
the condition to:

if (!offset && offset != 0)

I could have used (offset === false) , but that wouldn't catch null values.

Anyone know if this is a bug, or whether I'm misunderstanding something and it is intended

Another solution would have been to create a new fileWriter object each time, but somehow
I don't think that was the best way to go ;)


This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:!default.jspa
For more information on JIRA, see:


View raw message