@@ -297,28 +297,34 @@ operator()(route_params& rp) const
297297 // Calculate how much to send
298298 std::int64_t remaining = info.range_end - info.range_start + 1 ;
299299
300- // Stream file content
301- constexpr std::size_t buf_size = 16384 ;
302- char buffer[buf_size];
303-
300+ // Stream file content using serializer's internal buffer
304301 while (remaining > 0 )
305302 {
303+ capy::mutable_buffer arr[1 ];
304+ auto bufs = rp.res_body .prepare (arr);
305+ if (bufs.empty ())
306+ {
307+ auto [ec2] = co_await rp.res_body .commit (0 );
308+ if (ec2)
309+ co_return route_error (ec2);
310+ continue ;
311+ }
312+
306313 auto const to_read = static_cast <std::size_t >(
307- (std::min)(remaining, static_cast <std::int64_t >(buf_size)));
314+ (std::min)(remaining,
315+ static_cast <std::int64_t >(bufs[0 ].size ())));
308316
309- auto const n1 = f.read (buffer , to_read, ec);
317+ auto const n1 = f.read (bufs[ 0 ]. data () , to_read, ec);
310318 if (ec.failed () || n1 == 0 )
311319 break ;
312320
313- auto [ec2, n2] = co_await rp.res_body .write (
314- capy::const_buffer (buffer, n1));
315- (void )n2;
321+ auto [ec2] = co_await rp.res_body .commit (n1);
316322 if (ec2)
317323 co_return route_error (ec2);
318324 remaining -= static_cast <std::int64_t >(n1);
319325 }
320326
321- auto [ec3] = co_await rp.res_body .write_eof ( );
327+ auto [ec3] = co_await rp.res_body .commit_eof ( 0 );
322328 if (ec3)
323329 co_return route_error (ec3);
324330 co_return route_done;
0 commit comments