@@ -53,6 +53,7 @@ static struct argp_option options[] = { // NOLINT
5353 " critical, 6 = none. Default: 2." ,
5454 0 },
5555 {" tsi" , ' T' , " ID" , 0 , " The TSI to use for the FLUTE session (default: 16)" , 0 },
56+ {" output-path" , ' o' , " PATH" , 0 , " Directory to save received files" , 0 },
5657 {nullptr , 0 , nullptr , 0 , nullptr , 0 }};
5758
5859/* *
@@ -67,6 +68,7 @@ struct ft_arguments {
6768 unsigned log_level = 2 ; /* *< log level */
6869 char **files;
6970 uint64_t tsi = 16 ;
71+ const char *output_path = nullptr ;
7072};
7173
7274/* *
@@ -94,6 +96,9 @@ static auto parse_opt(int key, char *arg, struct argp_state *state) -> error_t {
9496 case ' T' :
9597 arguments->tsi = static_cast <uint64_t >(strtoul (arg, nullptr , 10 ));
9698 break ;
99+ case ' o' :
100+ arguments->output_path = arg;
101+ break ;
97102 default :
98103 return ARGP_ERR_UNKNOWN;
99104 }
@@ -160,13 +165,18 @@ auto main(int argc, char **argv) -> int {
160165 }
161166
162167 receiver.register_completion_callback (
163- [](std::shared_ptr<LibFlute::File> file) { // NOLINT
164- spdlog::info (" {} (TOI {}{}{}) has been received" ,
165- file->meta ().content_location , file->meta ().toi , file->meta ().etag .empty ()?" " :" , ETag = " , file->meta ().etag );
166- FILE* fd = fopen (file->meta ().content_location .c_str (), " wb" );
168+ [output_path = arguments.output_path ](std::shared_ptr<LibFlute::File> file) { // NOLINT
169+ std::string out_file = file->meta ().content_location ;
170+ if (output_path && std::strlen (output_path) > 0 ) {
171+ out_file = (std::filesystem::path (output_path) / std::filesystem::path (out_file).filename ()).string ();
172+ }
173+
174+ spdlog::info (" {} (TOI {}) has been received" ,
175+ out_file, file->meta ().toi );
176+ FILE *fd = fopen (out_file.c_str (), " wb" );
167177 fwrite (file->buffer (), 1 , file->length (), fd);
168178 fclose (fd);
169- });
179+ });
170180
171181 // Start the IO service
172182 io.run ();
0 commit comments