deanm0000 commented on issue #160: URL: https://github.com/apache/avro-rs/issues/160#issuecomment-2736970011
Thanks for the response. I just tried it out and I got it to work (I think) but I'm a bit confused how the marker works and not sure if I'm doing it right. I inferred from [this](https://github.com/apache/avro-rs/blob/c1c595a053d46f354102a3b4628d3c8600140307/avro/src/reader.rs#L598) that it's just the last 16 bytes of the file so I made this function to get the schema and marker ```rust fn get_schema_marker(file: &File) -> (Schema, [u8; 16]) { let mut fs_reader = BufReader::new(file); fs_reader .seek(SeekFrom::End(-16)) .expect("couldn't seek to end"); let mut buffer = [0u8; 16]; fs_reader .read_exact(&mut buffer) .expect("couldn't read exact"); fs_reader .seek(SeekFrom::Start(0)) .expect("couldn't seek to start"); let reader = Reader::new(fs_reader).unwrap(); let schema = reader.writer_schema().clone(); (schema, buffer) } ``` and then this one to append ```rust fn append_avro(test_file: &str) { let f = OpenOptions::new() .append(true) .read(true) .open(test_file) .expect("Unable to open file in append"); let (schema, marker) = get_schema_marker(&f); let mut writer = Writer::append_to(&schema, BufWriter::new(f), marker); let mut record = Record::new(&schema).unwrap(); record.put("field1", "goodbye"); writer.append(record).unwrap(); writer.into_inner().expect("failed append writer.into"); } ``` Do those make sense in a file context or is there anything glaringly wrong and/or unnecessary? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
