def readschemadata(bytes_io: io._io.BytesIO) -> fastavro._read.reader: """Read data that already has an Avro schema. Parameters ---------- bytes_io : `_io.BytesIO` Data to be decoded. Returns ------- `fastavro._read.reader` Iterator over records (`dict`) in an avro file. Examples ---------- Open an avro file, and read the schema and the records >>> with open(ztf_alert_sample, mode='rb') as file_data: ... data = readschemadata(file_data) ... # Read the schema ... schema = data.schema ... # data is an iterator ... for record in data: ... print(type(record)) <class 'dict'> """ bytes_io.seek(0) message = fastavro.reader(bytes_io) return message
def readSchemaData(bytes_io: io._io.BytesIO): """Read data that already has an Avro schema. Parameters ---------- bytes_io : `_io.BytesIO` Data to be decoded. Returns ------- `dict` Decoded data. """ bytes_io.seek(0) message = fastavro.reader(bytes_io) return message
def readAvroData(bytes_io: io._io.BytesIO, json_schema: dict) -> dict: """Read data and decode with a given Avro schema. Parameters ---------- bytes_io : `_io.BytesIO` Data to be decoded. json_schema : `dict` The reader Avro schema for decoding data. Returns ------- `dict` Decoded data. """ bytes_io.seek(0) message = fastavro.schemaless_reader(bytes_io, json_schema) return message