--- a/sites/irclogs.qmsk.net/log_source.py Sun Feb 08 02:29:23 2009 +0200
+++ b/sites/irclogs.qmsk.net/log_source.py Sun Feb 08 02:55:53 2009 +0200
@@ -63,7 +63,7 @@
# read offset
# XXX; why -2 ?
- offset = self.file.tell() - 2
+ size = offset = self.file.tell() - 2
# use this blocksize
BLOCKSIZE = 1024
@@ -73,21 +73,25 @@
# read a block at a time, backwards
while count > 0 and offset >= 0:
- # update offset
+ # update offset back one block
offset -= BLOCKSIZE
# normalize to zero
if offset < 0 :
offset = 0
- # seek backwards one block
+ # seek to offset
self.file.seek(offset)
# add the new block to our buffer
read_buf = self.file.read(BLOCKSIZE)
+ # XXX: trim off extra...
+ if len(read_buf) > BLOCKSIZE :
+ read_buf = read_buf[:BLOCKSIZE]
+
# make sure we got the right amount of data
- assert len(read_buf) == BLOCKSIZE, "read(%d) -> %d" % (BLOCKSIZE, len(read_buf))
+ assert len(read_buf) == BLOCKSIZE, "read(%d) @ %d/%d -> %d" % (BLOCKSIZE, offset, size, len(read_buf))
# add in our previous buf
buf = read_buf + buf
@@ -99,7 +103,7 @@
buf = buf_lines[0]
# add up to count lines to our lines buffer
- lines = buf_lines[1:count + 1] + lines
+ lines = buf_lines[-min(count, len(buf_lines) - 1):] + lines
# update count
count -= (len(buf_lines) - 1)