@@ -44,6 +44,14 @@ struct aws_parallel_input_stream *aws_parallel_input_stream_release(struct aws_p
4444 return NULL ;
4545}
4646
47+ int aws_parallel_input_stream_get_length (struct aws_parallel_input_stream * stream , int64_t * out_length ) {
48+ if (stream -> vtable -> get_length ) {
49+ return stream -> vtable -> get_length (stream , out_length );
50+ } else {
51+ return aws_raise_error (AWS_ERROR_UNSUPPORTED_OPERATION );
52+ }
53+ }
54+
4755struct aws_future_bool * aws_parallel_input_stream_read (
4856 struct aws_parallel_input_stream * stream ,
4957 uint64_t offset ,
@@ -68,7 +76,7 @@ struct aws_parallel_input_stream_from_file_impl {
6876 struct aws_event_loop_group * reading_elg ;
6977};
7078
71- static void s_para_from_file_destroy (struct aws_parallel_input_stream * stream ) {
79+ static void s_parallel_from_file_destroy (struct aws_parallel_input_stream * stream ) {
7280 struct aws_parallel_input_stream_from_file_impl * impl =
7381 AWS_CONTAINER_OF (stream , struct aws_parallel_input_stream_from_file_impl , base );
7482
@@ -102,6 +110,7 @@ static int s_read_from_file_impl(
102110 int rt_code = AWS_OP_ERR ;
103111 FILE * file_stream = aws_fopen_safe (file_path , s_readonly_bytes_mode );
104112 if (file_stream == NULL ) {
113+ AWS_LOGF_ERROR (AWS_LS_S3_GENERAL , "Failed to open file %s" , aws_string_c_str (file_path ));
105114 return AWS_OP_ERR ;
106115 }
107116
@@ -158,7 +167,7 @@ static void s_s3_parallel_from_file_read_task(struct aws_task *task, void *arg,
158167 aws_mem_release (impl -> base .alloc , read_task );
159168}
160169
161- struct aws_future_bool * s_para_from_file_read (
170+ struct aws_future_bool * s_parallel_from_file_read (
162171 struct aws_parallel_input_stream * stream ,
163172 uint64_t offset ,
164173 size_t max_length ,
@@ -199,9 +208,23 @@ struct aws_future_bool *s_para_from_file_read(
199208 return future ;
200209}
201210
211+ int s_parallel_from_file_get_length (struct aws_parallel_input_stream * stream , int64_t * length ) {
212+ struct aws_parallel_input_stream_from_file_impl * impl =
213+ AWS_CONTAINER_OF (stream , struct aws_parallel_input_stream_from_file_impl , base );
214+ FILE * file = aws_fopen_safe (impl -> file_path , s_readonly_bytes_mode );
215+ if (!file ) {
216+ return AWS_OP_ERR ;
217+ }
218+
219+ int ret_val = aws_file_get_length (file , length );
220+ fclose (file );
221+ return ret_val ;
222+ }
223+
202224static struct aws_parallel_input_stream_vtable s_parallel_input_stream_from_file_vtable = {
203- .destroy = s_para_from_file_destroy ,
204- .read = s_para_from_file_read ,
225+ .destroy = s_parallel_from_file_destroy ,
226+ .read = s_parallel_from_file_read ,
227+ .get_length = s_parallel_from_file_get_length ,
205228};
206229
207230struct aws_parallel_input_stream * aws_parallel_input_stream_new_from_file (
@@ -219,7 +242,7 @@ struct aws_parallel_input_stream *aws_parallel_input_stream_new_from_file(
219242 if (!aws_path_exists (impl -> file_path )) {
220243 /* If file path not exists, raise error from errno. */
221244 aws_translate_and_raise_io_error (errno );
222- s_para_from_file_destroy (& impl -> base );
245+ s_parallel_from_file_destroy (& impl -> base );
223246 return NULL ;
224247 }
225248
0 commit comments