MCPcopy Index your code
hub / github.com/python/cpython / _read_gzip_header

Function _read_gzip_header

Lib/gzip.py:487–521  ·  view source on GitHub ↗

Read a gzip header from `fp` and progress to the end of the header. Returns last mtime if header was present or None otherwise.

(fp)

Source from the content-addressed store, hash-verified

485
486
487def _read_gzip_header(fp):
488 '''Read a gzip header from `fp` and progress to the end of the header.
489
490 Returns last mtime if header was present or None otherwise.
491 '''
492 magic = fp.read(2)
493 if magic == b'':
494 return None
495
496 if magic != b'\037\213':
497 raise BadGzipFile('Not a gzipped file (%r)' % magic)
498
499 (method, flag, last_mtime) = struct.unpack("<BBIxx", _read_exact(fp, 8))
500 if method != 8:
501 raise BadGzipFile('Unknown compression method')
502
503 if flag & FEXTRA:
504 # Read & discard the extra field, if present
505 extra_len, = struct.unpack("<H", _read_exact(fp, 2))
506 _read_exact(fp, extra_len)
507 if flag & FNAME:
508 # Read and discard a null-terminated string containing the filename
509 while True:
510 s = fp.read(1)
511 if not s or s==b'\000':
512 break
513 if flag & FCOMMENT:
514 # Read and discard a null-terminated string containing a comment
515 while True:
516 s = fp.read(1)
517 if not s or s==b'\000':
518 break
519 if flag & FHCRC:
520 _read_exact(fp, 2) # Read & discard the 16-bit header CRC
521 return last_mtime
522
523
524class _GzipReader(_streams.DecompressReader):

Callers 2

_read_gzip_headerMethod · 0.85
decompressFunction · 0.85

Calls 4

BadGzipFileClass · 0.85
_read_exactFunction · 0.85
unpackMethod · 0.80
readMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…