Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for binary files #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions tail.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

class Tail(object):
''' Represents a tail command. '''
def __init__(self, tailed_file):
def __init__(self, tailed_file, open_mode = 'r'):
''' Initiate a Tail instance.
Check for file validity, assigns callback function to standard out.

Expand All @@ -38,6 +38,7 @@ def __init__(self, tailed_file):
self.check_file_validity(tailed_file)
self.tailed_file = tailed_file
self.callback = sys.stdout.write
self.open_mode = open_mode

def follow(self, s=1):
''' Do a tail follow. If a callback function is registered it is called with every new line.
Expand All @@ -46,7 +47,7 @@ def follow(self, s=1):
Arguments:
s - Number of seconds to wait between each iteration; Defaults to 1. '''

with open(self.tailed_file) as file_:
with open(self.tailed_file, self.open_mode) as file_:
# Go to the end of file
file_.seek(0,2)
while True:
Expand Down