|
4 | 4 | #include <iostream> |
5 | 5 | #include <vector> |
6 | 6 |
|
7 | | -#include <sparrow_ipc/deserialize.hpp> |
8 | | -#include <sparrow_ipc/memory_output_stream.hpp> |
9 | | -#include <sparrow_ipc/serializer.hpp> |
10 | | -#include <sparrow_ipc/stream_file_serializer.hpp> |
| 7 | +#include "integration_tools.hpp" |
11 | 8 |
|
12 | 9 | /** |
13 | 10 | * @brief Reads an Arrow IPC file and outputs the serialized Arrow IPC stream to a file. |
@@ -36,37 +33,52 @@ int main(int argc, char* argv[]) |
36 | 33 |
|
37 | 34 | try |
38 | 35 | { |
39 | | - // Read the Arrow file |
| 36 | + if (!std::filesystem::exists(input_path)) |
| 37 | + { |
| 38 | + std::cerr << "Error: Input file not found: " << input_path << "\n"; |
| 39 | + return EXIT_FAILURE; |
| 40 | + } |
| 41 | + |
40 | 42 | std::ifstream input_file(input_path, std::ios::binary); |
41 | | - if (!input_file) |
| 43 | + if (!input_file.is_open()) |
42 | 44 | { |
43 | 45 | std::cerr << "Error: Could not open input file: " << input_path << "\n"; |
44 | 46 | return EXIT_FAILURE; |
45 | 47 | } |
46 | | - |
| 48 | + |
47 | 49 | const std::vector<uint8_t> file_data( |
48 | 50 | (std::istreambuf_iterator<char>(input_file)), |
49 | | - (std::istreambuf_iterator<char>()) |
| 51 | + std::istreambuf_iterator<char>() |
50 | 52 | ); |
51 | 53 | input_file.close(); |
52 | 54 |
|
53 | | - const auto batches = sparrow_ipc::deserialize_file(file_data); |
54 | | - |
55 | | - std::vector<uint8_t> stream_data; |
56 | | - sparrow_ipc::memory_output_stream mem_stream(stream_data); |
57 | | - sparrow_ipc::serializer serializer(mem_stream); |
58 | | - serializer << batches << sparrow_ipc::end_stream; |
59 | | - |
| 55 | + if (file_data.empty()) |
| 56 | + { |
| 57 | + std::cerr << "Error: Input file is empty.\n"; |
| 58 | + return EXIT_FAILURE; |
| 59 | + } |
| 60 | + |
| 61 | + const std::vector<uint8_t> stream_data = integration_tools::file_to_stream(file_data); |
| 62 | + |
60 | 63 | std::ofstream output_file(output_path, std::ios::binary); |
61 | | - if (!output_file) |
| 64 | + if (!output_file.is_open()) |
62 | 65 | { |
63 | 66 | std::cerr << "Error: Could not open output file: " << output_path << "\n"; |
64 | 67 | return EXIT_FAILURE; |
65 | 68 | } |
66 | | - |
67 | | - output_file.write(reinterpret_cast<const char*>(stream_data.data()), static_cast<std::streamsize>(stream_data.size())); |
| 69 | + |
| 70 | + output_file.write( |
| 71 | + reinterpret_cast<const char*>(stream_data.data()), |
| 72 | + static_cast<std::streamsize>(stream_data.size()) |
| 73 | + ); |
68 | 74 | output_file.close(); |
69 | 75 |
|
| 76 | + if (!output_file.good()) |
| 77 | + { |
| 78 | + std::cerr << "Error: Failed to write to output file: " << output_path << "\n"; |
| 79 | + return EXIT_FAILURE; |
| 80 | + } |
| 81 | + |
70 | 82 | return EXIT_SUCCESS; |
71 | 83 | } |
72 | 84 | catch (const std::exception& e) |
|
0 commit comments