MCPcopy Index your code
hub / github.com/RustPython/RustPython / _read_gzip_header

Function _read_gzip_header

Lib/gzip.py:489–523  ·  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

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

Callers 2

_read_gzip_headerMethod · 0.85
decompressFunction · 0.85

Calls 4

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

Tested by

no test coverage detected