@@ -48,8 +48,6 @@ using clp_s::CommandLineArguments;
4848
4949namespace {
5050
51- size_t max_ir_buffer_size = 1'000'000'000 ;
52-
5351/* *
5452 * Compresses the input files specified by the command line arguments into an archive.
5553 * @param command_line_arguments
@@ -87,6 +85,17 @@ auto run_serializer(clp_s::JsonToIRParserOption const& option, std::string path)
8785 */
8886auto generate_ir (CommandLineArguments const & command_line_arguments) -> bool;
8987
88+ /* *
89+ * Fill in JsonParserOption instance based on command line user input
90+ * @param command_line_arguments
91+ * @param option
92+ * @return Whether setup was succesful
93+ */
94+ auto setup_compression_options (
95+ CommandLineArguments const & command_line_arguments,
96+ clp_s::JsonParserOption& option
97+ ) -> bool;
98+
9099/* *
91100 * Compresses the input IR files specified by the command line arguments into an archive.
92101 * @param command_line_arguments
@@ -238,7 +247,7 @@ auto run_serializer(clp_s::JsonToIRParserOption const& option, std::string path)
238247 return false ;
239248 }
240249 flush_and_clear_serializer_buffer (serializer, ir_buf);
241- if (ir_buf.size () >= max_ir_buffer_size) {
250+ if (ir_buf.size () >= option. max_ir_buffer_size ) {
242251 total_size = total_size + ir_buf.size ();
243252 zc.write (reinterpret_cast <char *>(ir_buf.data ()), ir_buf.size ());
244253 zc.flush ();
@@ -278,11 +287,13 @@ auto generate_ir(CommandLineArguments const& command_line_arguments) -> bool {
278287 option.file_paths = command_line_arguments.get_file_paths ();
279288 option.irs_dir = irs_dir.string ();
280289 option.max_document_size = command_line_arguments.get_max_document_size ();
290+ option.max_ir_buffer_size = command_line_arguments.get_max_ir_buffer_size ();
281291 option.compression_level = command_line_arguments.get_compression_level ();
282292 option.encoding = command_line_arguments.get_encoding_type ();
283293
284294 if (false == clp_s::FileUtils::validate_path (option.file_paths )) {
285- exit (1 );
295+ SPDLOG_ERROR (" Invalid file path(s) provided" );
296+ return false ;
286297 }
287298
288299 std::vector<std::string> all_file_paths;
@@ -304,9 +315,11 @@ auto generate_ir(CommandLineArguments const& command_line_arguments) -> bool {
304315 return true ;
305316}
306317
307- auto ir_compress (CommandLineArguments const & command_line_arguments) -> bool {
318+ auto setup_compression_options (
319+ CommandLineArguments const & command_line_arguments,
320+ clp_s::JsonParserOption& option
321+ ) -> bool {
308322 auto archives_dir = std::filesystem::path (command_line_arguments.get_archives_dir ());
309-
310323 // Create output directory in case it doesn't exist
311324 try {
312325 std::filesystem::create_directory (archives_dir.string ());
@@ -318,8 +331,6 @@ auto ir_compress(CommandLineArguments const& command_line_arguments) -> bool {
318331 );
319332 return false ;
320333 }
321-
322- clp_s::JsonParserOption option{};
323334 option.file_paths = command_line_arguments.get_file_paths ();
324335 option.archives_dir = archives_dir.string ();
325336 option.target_encoded_size = command_line_arguments.get_target_encoded_size ();
@@ -340,6 +351,14 @@ auto ir_compress(CommandLineArguments const& command_line_arguments) -> bool {
340351 db_config.get_metadata_table_prefix ()
341352 );
342353 }
354+ return true ;
355+ }
356+
357+ auto ir_compress (CommandLineArguments const & command_line_arguments) -> bool {
358+ clp_s::JsonParserOption option{};
359+ if (false == setup_compression_options (command_line_arguments, option)) {
360+ return false ;
361+ }
343362
344363 clp_s::JsonParser parser (option);
345364 if (false == parser.parse_from_ir ()) {
0 commit comments