def parse_bgzf_header(f):
cur_pos = f.tell()
header_fmt = "BBBBIBBH"
d = f.read(12)
# We are at EOF when read returns an empty string
if d == '':
return None
header = struct.unpack(header_fmt, d)
# Check for a valid gzip header
if header[0] != 31 or header[1] != 139:
raise Exception("Not a valid gzip header")
xlen = header[7]
bsize = get_bsize(f, f.tell(), xlen)
next_pos = cur_pos + bsize + 1
f.seek(next_pos)
return next_pos
评论列表
文章目录