Skip to content

Commit e16ac74

Browse files
author
rkern
committed
BUG: .gz files don't report the right correct length. Thanks to Brandon Craig Rhodes for the fix.
git-svn-id: https://svn.enthought.com/svn/sandbox/grin/trunk@78 b5260ef8-a2c4-4e91-82fd-f242746c304a
1 parent 0d7caed commit e16ac74

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

grin.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,17 @@ def do_grep(self, fp):
304304
"""
305305
context = []
306306
line_count = 0
307-
try:
308-
status = os.fstat(fp.fileno())
309-
if stat.S_ISREG(status.st_mode):
310-
fp_size = status.st_size
311-
else:
307+
if isinstance(fp, gzip.GzipFile):
308+
fp_size = None # gzipped data is usually longer than the file
309+
else:
310+
try:
311+
status = os.fstat(fp.fileno())
312+
if stat.S_ISREG(status.st_mode):
313+
fp_size = status.st_size
314+
else:
315+
fp_size = None
316+
except AttributeError: # doesn't support fileno()
312317
fp_size = None
313-
except AttributeError: # doesn't support fileno()
314-
fp_size = None
315318

316319
block = self.read_block_with_context(None, fp, fp_size)
317320
while block.end > block.start:

0 commit comments

Comments
 (0)