/usr/lib/perl5/KinoSearch1/Index/CompoundFileReader.pm is in libkinosearch1-perl 1.00-1build3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | package KinoSearch1::Index::CompoundFileReader;
use strict;
use warnings;
use KinoSearch1::Util::ToolSet;
use base qw( KinoSearch1::Store::InvIndex ); # !!
BEGIN {
__PACKAGE__->init_instance_vars(
# members / constructor params
invindex => undef,
seg_name => undef,
# members
instream => undef,
entries => undef,
);
}
use KinoSearch1::Store::InStream;
sub init_instance {
my $self = shift;
my ( $seg_name, $invindex ) = @{$self}{ 'seg_name', 'invindex' };
# read in names and lengths for all the "files" within the compound file
my $instream = $self->{instream}
= $invindex->open_instream("$seg_name.cfs");
my $num_entries = $instream->lu_read('V');
my @offsets_and_names = $instream->lu_read( 'QT' x $num_entries );
my $offset = shift @offsets_and_names;
my %entries;
while (@offsets_and_names) {
my $filename = shift @offsets_and_names;
my $next_offset = shift @offsets_and_names || $instream->length;
$entries{$filename} = {
offset => $offset,
len => $next_offset - $offset,
};
$offset = $next_offset;
}
$self->{entries} = \%entries;
}
sub open_instream {
my ( $self, $filename ) = @_;
my $entry = $self->{entries}{$filename};
croak("filename '$filename' is not accessible") unless defined $entry;
open( my $duped_fh, '<&=', $self->{instream}->get_fh )
or confess("Couldn't dupe filehandle: $!");
return KinoSearch1::Store::InStream->new( $duped_fh, $entry->{offset},
$entry->{len} );
}
sub slurp_file {
my ( $self, $filename ) = @_;
my $instream = $self->open_instream($filename);
my $contents
= $instream->lu_read( 'a' . $self->{entries}{$filename}{len} );
$instream->close;
return $contents;
}
sub close { shift->{instream}->close }
1;
__END__
=begin devdocs
=head1 NAME
KinoSearch1::Index::CompoundFileReader - read from a compound file
=head1 SYNOPSIS
my $comp_file_reader = KinoSearch1::Index::CompoundFileReader->new(
invindex => $invindex,
filename => "$seg_name.cfs",
);
my $instream = $comp_file_reader->open_instream("$seg_name.fnm");
=head1 DESCRIPTION
A CompoundFileReader provides access to the files contained within the
compound file format written by CompoundFileWriter. The InStream objects it
spits out behave largely like InStreams opened against discrete files --
$instream->seek(0) seeks to the beginning of the sub-file, not the beginning
of the compound file.
=head1 COPYRIGHT
Copyright 2005-2010 Marvin Humphrey
=head1 LICENSE, DISCLAIMER, BUGS, etc.
See L<KinoSearch1> version 1.00.
=end devdocs
=cut
|