What would be the most efficient way to read the beginning and the end of a huge file (binary or text) in given number of bytes?
Example:
=head2 read_file_contents(file, limit)
Given a filename, returns its partial content in bytes, with number of truncated bytes
=cut
sub read_file_contents
{
my ($file, $limit) = @_;
my $rv;
# Starting and ending number of bytes to read
$limit = $limit / 2;
# Reading beginning of file
my $start;
# code goes here
# Reading end of a file
my $end;
# code goes here
$rv = $start . "\n\n\n truncated N bytes of data \n\n\n" . $end;
return $rv;
}
The main goal is to be able quickly, without processing the whole file, fetch its start and end bytes effectively. It is not a problem to read a whole file and then substr it the needed way but it is not going to work fine with files of size 10 Gb+.
Any solutions would be appreciated.