From 40bd571489518695a09109bf1a5bc897cbd9423d Mon Sep 17 00:00:00 2001 From: QLeelulu Date: Fri, 23 Aug 2013 18:04:21 +0800 Subject: [PATCH] add Tell to return the file's current position, like stdio's ftell(). --- tail.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tail.go b/tail.go index 36cb4b9..19e1a38 100644 --- a/tail.go +++ b/tail.go @@ -91,6 +91,16 @@ func TailFile(filename string, config Config) (*Tail, error) { return t, nil } +// Return the file's current position, like stdio's ftell(). +// But this value is not very accurate. +func (tail *Tail) Tell() (offser int64, err error) { + offset, err = tail.file.Seek(0, os.SEEK_CUR) + if err == nil { + offset -= int64(tail.reader.Buffered()) + } + return +} + // Stop stops the tailing activity. func (tail *Tail) Stop() error { tail.Kill(nil)