38 |
|
|
39 |
use html; |
use html; |
40 |
our $static_pids; |
our $static_pids; |
41 |
|
use progress_bar; |
|
use Time::HiRes qw/time/; |
|
42 |
|
|
43 |
sub static { |
sub static { |
44 |
my ($client,$path) = @_; |
my ($client,$path) = @_; |
70 |
my $buff; |
my $buff; |
71 |
my $pos = 0; |
my $pos = 0; |
72 |
|
|
|
STDERR->autoflush(1); |
|
73 |
warn "static $path $type $size block: $block\n"; |
warn "static $path $type $size block: $block\n"; |
74 |
|
|
75 |
my $start_t = time(); |
progress_bar::start; |
|
my $last_t = $start_t; |
|
76 |
|
|
77 |
while( my $len = read $fh, $buff, $block ) { |
while( my $len = read $fh, $buff, $block ) { |
78 |
print $client $buff; |
print $client $buff; |
79 |
$client->flush; |
$client->flush; |
80 |
$pos += $len; |
$pos += $len; |
81 |
my $t = time(); |
progress_bar::tick( $path, $pos, $size ); |
|
next unless $t - $last_t > 0.75; |
|
|
$last_t = $t; |
|
|
my $speed = ( $pos ) / ( $t - $start_t ); |
|
|
printf STDERR "%s %d/%d %.2f%% %.2f K/s ETA %.1fs \r" |
|
|
, $path, $pos |
|
|
, $size, $pos * 100 / $size |
|
|
, $speed / 1024 |
|
|
, ( $size - $pos ) / $speed |
|
|
; |
|
82 |
} |
} |
83 |
close($fh); |
close($fh); |
84 |
close($client); |
close($client); |