Mojo :: UserAgentを使用してこのようなものを記述し、同等のオプション(、、、、)を設定する方法Range
はありますか?:content_file
:content_cb
size_hint
#!/usr/bin/env perl
use warnings;
use 5.12.0;
use LWP::UserAgent;
use File::Basename;
my $url = 'ftp://ftp.vim.org/pub/vim/runtime/spell/en.utf-8.spl';
my $file = basename $url;
my $ua = LWP::UserAgent->new();
my $bytes = 0;
open my $fh, '>>:raw', $file or die $!;
my $res = $ua->get(
$url,
'Range' => "bytes=$bytes-",
':content_cb' => sub {
my ( $chunk, $res, $proto ) = @_;
print $fh $chunk;
state $old_size = 0;
my $size = tell $fh;
my $total;
say 'chunk size :', $size - $old_size;
if ( $total = $res->header( 'Content-Length' ) ) {
say 'total size : ', $total;
say 'downloaded : ', $size;
say 'remaining : ', $total - $size;
}
say "";
$old_size = $size;
}
);
close $fh;
say $res->status_line;