def pad_or_truncate(to_pad, length):
    """
    Truncate or pad (with zeros) a GT text field
    :param to_pad: text to pad
    :type to_pad: either string or bytes
    :param length: grow or shrink input to this length ("Procrustean bed")
    :type length: int
    :return: processed text field
    :rtype:
    """
    if isinstance(to_pad, str):
        to_pad = to_pad.encode('latin-1')
    return to_pad.ljust(length, b'\0')[0:length]