incubator-callback-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Simon MacDonald (Resolved) (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (CB-472) FileWriter.seek(0) does not actually seek to the beginning of the file.
Date Tue, 10 Apr 2012 14:03:19 GMT

     [ https://issues.apache.org/jira/browse/CB-472?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Simon MacDonald resolved CB-472.
--------------------------------

       Resolution: Fixed
    Fix Version/s: 1.6.0
    
> FileWriter.seek(0) does not actually seek to the beginning of the file.
> -----------------------------------------------------------------------
>
>                 Key: CB-472
>                 URL: https://issues.apache.org/jira/browse/CB-472
>             Project: Apache Callback
>          Issue Type: Bug
>          Components: CordovaJS
>    Affects Versions: 1.0.0, 1.1.0, 1.2.0, 1.3.0, 1.4.0, 1.5.0
>            Reporter: Simon MacDonald
>            Assignee: Simon MacDonald
>             Fix For: 1.6.0
>
>
> Tom Jenkins tomkevinjenkins@gmail.com via googlegroups.com 
> 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:
> writer.seek(0);
> writer.write(data);
> What actually happens is the data gets appended instead. I found this is because when
I call writer.seek(0), it's not actually seeking, because of this check in FileWriter.prototype.seek:
> if (!offset) {
>     return;
> }
> 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
behaviour?
> 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 ;)
> Thanks

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message