fseek In Compressed Files

Ayushi Dalmia ayushidalmia2604 at gmail.com
Sat Feb 1 06:50:21 CET 2014


On Thursday, January 30, 2014 9:51:28 PM UTC+5:30, Peter Otten wrote:
> Serhiy Storchaka wrote:
> 
> 
> 
> > 30.01.14 13:28, Peter Otten написав(ла):
> 
> >> Ayushi Dalmia wrote:
> 
> >>
> 
> >>> I need to randomly access a bzip2 or gzip file. How can I set the offset
> 
> >>> for a line and later retreive the line from the file using the offset.
> 
> >>> Pointers in this direction will help.
> 
> >>
> 
> >> with gzip.open(filename) as f:
> 
> >>      f.seek(some_pos)
> 
> >>      print(f.readline())
> 
> >>      f.seek(some_pos)
> 
> >>      print(f.readline())
> 
> >>
> 
> >> seems to work as expected. Can you tell a bit more about your usecase (if
> 
> >> it isn't covered by that basic example)?
> 
> > 
> 
> > I don't recommend to seek backward in compressed file. This is very
> 
> > inefficient operation.
> 
> 
> 
> Do you know an efficient way to implement random access for a bzip2 or gzip 
> 
> file?

Nothing that I know of.



More information about the Python-list mailing list