I am reading a growing file and showing its contents in the browser .. here 
is my implementation for reading the file

 //start watching the file
                        fs.watchFile(filename, {persistent:true, 
interval:1000}, function(curr, prev){
                                if(prev.size > curr.size)       
callback(null);
                                //open stream
                                var stream = fs.createReadStream(filename, 
{start:prev.size, end:curr.size, encoding:'utf8'});
                                stream.on('data', function(data){
                                        //emit new data
                                        socket.emit('log', fileId, 
data.split('\r\n'));
                                });
                                stream.on('error', function(err){
                                        if(err) throw err;
                                });
                        });

this seems to work fine overall but for some strange reason it cant parse 
out some lines that are added to the file and the lines dont seem to be 
consistent .. e.g. the same line will be read fine if it shows up again but 
every once in a while it just reads the whole line as null characters and 
emits data as something like

debug: websocket writing 
5:::{"name":"log","args":["coi-prod_wom201207260log",["\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"]]}

any ideas whats going on here

Thanks
Adeel

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to