arrow_stream_to_file/arrow-stream-to-file.rs
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership
3// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements
4
5//! Converts an Arrow IPC stream to an Arrow IPC file.
6
7use std::io;
8
9use arrow::error::Result;
10use arrow::ipc::reader::StreamReader;
11use arrow::ipc::writer::FileWriter;
12
13fn main() -> Result<()> {
14 let mut arrow_stream_reader = StreamReader::try_new(io::stdin(), None)?;
15 let schema = arrow_stream_reader.schema();
16
17 let mut writer = FileWriter::try_new(io::stdout(), &schema)?;
18
19 arrow_stream_reader.try_for_each(|batch| writer.write(&batch?))?;
20 writer.finish()?;
21
22 Ok(())
23}