IO-Mark
view release on metacpan or search on metacpan
lib/IO/Mark.pm view on Meta::CPAN
my ($width, $height) = get_image_size( $socket );
# ...but the data we send here will be missing whatever header
# bytes get_image_size consumed.
send_image_data( $width, $height, $socket );
}
You could buffer the entire image in a file, open the file and pass that
handle to C<get_image_size>. That works but means that we can't compute
the image size until we have the whole image. If instead of an image
file we were dealing with streaming audio the input stream might be
effectively infinite - which would make caching it in a file
inconvenient.
We could rewrite C<get_image_size> to cache whatever data it reads from
the socket. Then we could send that data before sending the remainder of
the data from the socket. That probably means digging around inside a
function we didn't write and coupling its interface tightly to our
application. It'd be good to avoid that.
Here's the solution:
( run in 0.231 second using v1.01-cache-2.11-cpan-4d50c553e7e )