Skip to content
Snippets Groups Projects
Commit cc389ea7 authored by Andy Yates's avatar Andy Yates
Browse files

Faster slurp. Cannot apply to gzip because the the handle isn't open right...

Faster slurp. Cannot apply to gzip because the the handle isn't open right away and you can't ask for the size via -s if its not open
parent 384d9b35
No related branches found
No related tags found
No related merge requests found
......@@ -131,12 +131,19 @@ eval {
sub slurp {
my ($file, $want_ref, $binary) = @_;
my $contents;
my $contents = q{};
work_with_file($file, 'r', sub {
my ($fh) = @_;
local $/ = undef;
binmode($fh) if $binary;
$contents = <$fh>;
my $size_left = -s $fh;
while( $size_left > 0 ) {
my $read_cnt = sysread($fh, $contents, $size_left, length($contents));
unless( $read_cnt ) {
throw "read error in file $file: $!" ;
last;
}
$size_left -= $read_cnt ;
}
return;
});
return ($want_ref) ? \$contents : $contents;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment