paleolimbot commented on code in PR #585:
URL: https://github.com/apache/arrow-nanoarrow/pull/585#discussion_r1718638971
##########
src/nanoarrow/ipc/writer.c:
##########
@@ -329,3 +364,62 @@ ArrowErrorCode ArrowIpcWriterWriteArrayStream(struct
ArrowIpcWriter* writer,
ArrowArrayViewReset(&array_view);
return NANOARROW_OK;
}
+
+#define NANOARROW_IPC_FILE_PADDED_MAGIC "ARROW1\0"
+
+ArrowErrorCode ArrowIpcWriterStartFile(struct ArrowIpcWriter* writer,
+ struct ArrowError* error) {
+ NANOARROW_DCHECK(writer != NULL && writer->private_data != NULL);
+
+ struct ArrowIpcWriterPrivate* private =
+ (struct ArrowIpcWriterPrivate*)writer->private_data;
+
+ NANOARROW_DCHECK(!private->writing_file && private->bytes_written == 0);
+
+ struct ArrowBufferView magic = {
+ .data.data = NANOARROW_IPC_FILE_PADDED_MAGIC,
+ .size_bytes = sizeof(NANOARROW_IPC_FILE_PADDED_MAGIC),
+ };
+ NANOARROW_RETURN_NOT_OK(
+ ArrowIpcOutputStreamWrite(&private->output_stream, magic, error));
+
+ private->writing_file = 1;
+ private->bytes_written = magic.size_bytes;
+ return NANOARROW_OK;
+}
+
+ArrowErrorCode ArrowIpcWriterFinalizeFile(struct ArrowIpcWriter* writer,
+ struct ArrowError* error) {
+ NANOARROW_DCHECK(writer != NULL && writer->private_data != NULL);
+
+ struct ArrowIpcWriterPrivate* private =
+ (struct ArrowIpcWriterPrivate*)writer->private_data;
+
+ NANOARROW_DCHECK(private->writing_file);
+
+ NANOARROW_ASSERT_OK(ArrowBufferResize(&private->buffer, 0, 0));
+ NANOARROW_RETURN_NOT_OK(
+ ArrowIpcEncoderEncodeFooter(&private->encoder, &private->footer, error));
+ NANOARROW_RETURN_NOT_OK_WITH_ERROR(
+ ArrowIpcEncoderFinalizeBuffer(&private->encoder, /*encapsulate=*/0,
+ &private->buffer),
+ error);
+
+ _NANOARROW_CHECK_RANGE(private->buffer.size_bytes, 0, INT32_MAX);
+ int32_t size = (int32_t) private->buffer.size_bytes;
+ struct ArrowStringView magic =
ArrowCharView(NANOARROW_IPC_FILE_PADDED_MAGIC);
Review Comment:
I am fairly sure that this will only append 6 bytes to the end of the file
(and I think you want 8?)
--
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]