NAME

Warehouse::Stream -- API for retrieving files from streams in the warehouse.


VERSION

Version 0.01


SYNOPSIS

 use Warehouse::Stream;
 my $stream = Warehouse::Stream->new (whc => $whc,
                                      hash => \@blocklist);


METHODS

new

 my $stream = Warehouse::Stream->new (whc => $whc,
                                      hash => \@blocklist);
 my $stream = Warehouse::Stream->new (whc => $whc,
                                      subdir => $line_from_manifest);
 my $stream = Warehouse::Stream->new (whc => $whc);

Creates a new stream. Returns the new object on success. Dies on failure.

name

 my $name = $stream->name;

Get this stream's name (aka subdirname).

 $stream->name ($newname);

Set the stream's name.

as_string

 my $one_line_of_manifest = $stream->as_string;

Returns a newline-terminated string which can be included as a line in a manifest, and passed as a ``subdir'' to new.

as_key

 my $key = $stream->as_key;

Returns a key (comma-separated list of hashes) -- like as_string, but no subdir name or filenames, and commas instead of spaces.

clear

 $stream->clear;

Empty the stream of all data and files, presumably in preparation for a sequence of write_start, write_data, write_finish, and as_string operations.

write_hint

 $stream->write_hint (keep => 1);

write_start

 $stream->write_start ($filename);

Add a file to the end of the stream. This will be the ``current file'' when you use write_data.

Use clear first.

write_data

 $stream->write_data ($dataref);

Append data to the current (last) file in the stream. This dies if you didn't use write_start to indicate a filename.

write_finish

 $stream->write_finish;

Indicate that all data belonging to the current file has been written with write_data.

The data does not necessarily get stored in the warehouse until you call as_string. (Of course, you would never be able to retrieve it without as_string anyway.)

rewind

 $stream->rewind;

Go [back] to the first file/block in the stream.

file_next

 $stream->rewind;
 while (my ($pos, $size, $filename) = $stream->file_next)
 {
   last if !defined $pos;
   $stream->seek ($pos);
   while (my $dataref = $stream->read_until ($pos + $size))
   {
     # process data ($$dataref) from file ($filename)
   }
 }

seek

    $stream->seek ($pos);

Seeks forward to $pos bytes from the beginning of the stream. Dies on failure (eg. stream not long enough, or already past $pos).

read_until

    while (my $dataref = $stream->read_until ($endpos))
    {
        print $$dataref;
    }
    while (my $dataref = $stream->read_until ($endpos, "\n"))
    {
        print $$dataref;
    }
    while (my $dataref = $stream->read_until (undef, "\n"))
    {
        print $$dataref;
    }

Read data from stream until position $endpos is reached, or until the given end-of-record delimiter is reached.

If a delimiter is specified, then either $$dataref will end with the delimiter, or it will contain all data up to $endpos.

If a delimiter is not specified, and $endpos has not already been reached, then $$dataref will have some data; but it will not necessarily contain all data up to $endpos.

tell

    my $currentpos = $stream->tell;