def _check_magic(f):
    """Determines file type from leading bytes."""
    # CDF
    f.seek(0)
    CDF = f.read(3)
    if CDF == 'CDF':
        VERSION_BYTE = ord(f.read(1))
        if VERSION_BYTE == 1:
            return 'NetCDF Classic'
        elif VERSION_BYTE == 2:
            return 'NetCDF 64-bit'
        return None
    # HDF
    HDF_MAGIC = b"\x89HDF\r\n\x1a\n"
    f.seek(0)
    HDF = f.read(8)
    if HDF == HDF_MAGIC:
        return 'HDF'

    # PKZIP
    ZIP_MAGIC = b"\x50\x4b\x03\x04"
    f.seek(0)
    ZIP = f.read(4)
    if ZIP == ZIP_MAGIC:
        return 'ZIP'
    return None