Yeah if the file is being replaced or truncated you will need to handle
that differently. The code I posted is fine for the simple case of a unique
file being uploaded, but obviously your case may be more complex. This is
enough to get you started though! Gambate~

On Wed, Feb 8, 2012 at 10:14 PM, Shin Suzuki <[email protected]> wrote:

> Sorry, I mistook it. It went fine.
> In some programs, they replace a file instead of appending...
>
>
> 2012/2/9 Marcel Laverdet <[email protected]>
>
>> You certainly can do this without reopening the file. I'm using very
>> similar code to tail MySQL's binlogs. Are you sure that you're appending to
>> the file? Like others mentioned this does not handle reopening the file in
>> the case it's removed or whatever. If that is a constraint you will have to
>> handle it accordingly.
>>
>> I'm running the code I posted on your gist on OS X just fine. I'm running
>> it on a file and then in another terminal session running "echo hello >>
>> file" and then seeing the output in the other terminal. There is a two
>> second delay or so.
>>
>>
>> On Wed, Feb 8, 2012 at 9:37 PM, Shin Suzuki <[email protected]> wrote:
>>
>>> Marcel,
>>>
>>> Thanks for the sample code.
>>> Unfortunately, it didn't work in my environment (Mac OS X and CentOS).
>>> Essentially the code you've shown and my code is the same, in that both
>>> don't re-open the file.
>>> It seems we cannot fetch the added data without re-opening,
>>> Considering the overhead of opening the file in each "change" event,
>>> just spawning "tail -f" would be better as Matt says.
>>> What's difficult is that we cannot know at which line the child process
>>> of "tail -f" starts to read when the file is growing.
>>>
>>>
>>> 2012/2/9 Marcel Laverdet <[email protected]>
>>>
>>>> Matt keeps screaming race condition because conditions stated to not be
>>>> handled are not handled.
>>>>
>>>>
>>>> On Wed, Feb 8, 2012 at 5:09 PM, Mark Hahn <[email protected]> wrote:
>>>>
>>>>> That's not really a race, just a condition not covered.
>>>>>
>>>>>
>>>>> On Wed, Feb 8, 2012 at 3:08 PM, Matt <[email protected]> wrote:
>>>>>
>>>>>> There's a race between when you get the results from stat and re-open
>>>>>> the file. You know it's changed, you assume it has grown, so you re-open 
>>>>>> at
>>>>>> "last-byte-read" position. But what if between that time, the file got
>>>>>> truncated to zero, meaning you need to read from the start of the file?
>>>>>>
>>>>>> On Wed, Feb 8, 2012 at 4:36 PM, Adam Pritchard <
>>>>>> [email protected]> wrote:
>>>>>>
>>>>>>> Can you elaborate? I'm pretty new to JS/Node, so maybe I'm not
>>>>>>> seeing it.
>>>>>>>
>>>>>>> I recognize that the file reading isn't one-to-one with the
>>>>>>> notifications (i.e., many rapid file modifications will probably be
>>>>>>> processed in a single file read, and then following notifications won't
>>>>>>> have an effect until the file grows again), but I don't see that that's 
>>>>>>> a
>>>>>>> problem -- the data should still get processed in a timely fashion.
>>>>>>>
>>>>>>> On the other hand... my tests aren't running through successfully on
>>>>>>> two of three OSes, so there's certainly something not right...
>>>>>>>
>>>>>>> I'd appreciate any bugs or flaws you can point out.
>>>>>>>
>>>>>>> Adam
>>>>>>>
>>>>>>>
>>>>>>> On Wed, Feb 8, 2012 at 11:40 AM, Matt <[email protected]> wrote:
>>>>>>>
>>>>>>>> Still has a race condition in it.
>>>>>>>>
>>>>>>>>
>>>>>>>> On Tue, Feb 7, 2012 at 8:20 PM, Adam Pritchard <
>>>>>>>> [email protected]> wrote:
>>>>>>>>
>>>>>>>>> I've also been working on a little log-file-following (tail -f)
>>>>>>>>> node module.
>>>>>>>>>
>>>>>>>>> https://github.com/adam-p/text-file-follower/blob/master/lib/index.coffee
>>>>>>>>>
>>>>>>>>> I need it to work on Windows, so it's cross-platform. It works
>>>>>>>>> okay already, but I still have some stuff to do.
>>>>>>>>>
>>>>>>>>> The behaviour of fs.watch is a bit sketchy. For example...
>>>>>>>>> https://github.com/joyent/node/issues/search?q=fs.watch&state=open
>>>>>>>>>
>>>>>>>>> If I didn't need/want to support Windows I'd probably use
>>>>>>>>> fs.watchFile.
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> 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
>>>>>>>>>
>>>>>>>>
>>>>>>>>  --
>>>>>>>> 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
>>>>>>>>
>>>>>>>
>>>>>>>  --
>>>>>>> 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
>>>>>>>
>>>>>>
>>>>>>  --
>>>>>> 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
>>>>>>
>>>>>
>>>>>  --
>>>>> 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
>>>>>
>>>>
>>>>  --
>>>> 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
>>>>
>>>
>>>  --
>>> 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
>>>
>>
>>  --
>> 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
>>
>
>  --
> 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
>

-- 
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