MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _read_gzip_header

Function _read_gzip_header

tools/python-3.11.9-amd64/Lib/gzip.py:418–452  ·  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

416
417
418def _read_gzip_header(fp):
419 '''Read a gzip header from `fp` and progress to the end of the header.
420
421 Returns last mtime if header was present or None otherwise.
422 '''
423 magic = fp.read(2)
424 if magic == b'':
425 return None
426
427 if magic != b'\037\213':
428 raise BadGzipFile('Not a gzipped file (%r)' % magic)
429
430 (method, flag, last_mtime) = struct.unpack("<BBIxx", _read_exact(fp, 8))
431 if method != 8:
432 raise BadGzipFile('Unknown compression method')
433
434 if flag & FEXTRA:
435 # Read & discard the extra field, if present
436 extra_len, = struct.unpack("<H", _read_exact(fp, 2))
437 _read_exact(fp, extra_len)
438 if flag & FNAME:
439 # Read and discard a null-terminated string containing the filename
440 while True:
441 s = fp.read(1)
442 if not s or s==b'\000':
443 break
444 if flag & FCOMMENT:
445 # Read and discard a null-terminated string containing a comment
446 while True:
447 s = fp.read(1)
448 if not s or s==b'\000':
449 break
450 if flag & FHCRC:
451 _read_exact(fp, 2) # Read & discard the 16-bit header CRC
452 return last_mtime
453
454
455class _GzipReader(_compression.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