def toByteArray(structure, compressed): ''' Returns an MMTF-encoded byte array with optional gzip compression Returns: MMTF encoded and optionally gzipped structure data ''' byte_array = bytearray(msgpack.packb(MMTFEncoder.encode_data(structure))) if compressed: return gzip.compress(byte_array) else: return byte_array
def _to_byte_array(structure, compressed): '''Returns an MMTF-encoded byte array with optional gzip compression Returns ------- MMTF encoded and optionally gzipped structure data ''' if type(structure) == MmtfStructure: if not structure.alt_loc_set: structure = structure.set_alt_loc_list() byte_array = bytearray(msgpack.packb(MMTFEncoder.encode_data(structure), use_bin_type = True)) if compressed: return gzip.compress(byte_array) else: return byte_array