<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE></TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.5764" name=GENERATOR></HEAD>
<BODY>
<DIV><!-- Converted from text/plain format --><FONT face=Arial>Hi,</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial>I need to read the end of a 20 MB gzip archives (To
extract the date from the last line of a a gzipped log file).</FONT></DIV>
<DIV><FONT face=Arial>The solution I have below takes noticeable time to reach
the end of the gzip archive.</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial>Does anyone have a faster solution to read the last line
of a gzip archive ?</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial>Thanks,</FONT></DIV>
<DIV><FONT face=Arial>Ron.</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Courier>#!/usr/bin/env python</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Courier>import gzip</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Courier>path = "./a/20/mb/file.tgz"</FONT></DIV>
<DIV><FONT face=Courier></FONT> </DIV>
<DIV><FONT face=Courier>in_file = gzip.open(path, "r")<BR>first_line =
in_file.readline()<BR>print "first_line
==",first_line<BR>in_file.seek(-500)<BR>last_line =
in_file.readlines()[-1]<BR>print "last_line ==",last_line<BR></FONT></DIV>
<DIV><FONT face=Courier><BR></FONT> </DIV>
<DIV><FONT face=Arial color=#ff00ff></FONT> </DIV></BODY></HTML>