fd_retrieve#

Read one frozen structure from an open filehandle and reconstruct it.

Synopsis#

use Storable qw(store_fd fd_retrieve);
open my $fh, "<", "data.bin" or die $!;
my $data = fd_retrieve($fh);

What you get back#

A reference of the same kind written by the matching store_fd / nstore_fd. Byte order is auto-detected from the payload marker. fd_retrieve consumes exactly one framed record, leaving the filehandle positioned at the next one — repeat the call to read subsequent records.

Examples#

Drain a multi-record file:

open my $fh, "<", "log.bin" or die $!;
while (my $rec = fd_retrieve($fh)) {
    process($rec);
}

Read a single incoming message from a socket:

my $msg = fd_retrieve($socket);

Edge cases#

  • Returns undef if the filehandle has no readable file descriptor.

  • Returns undef on EOF or on a framing error (short read of the length prefix, truncated payload, corrupt header).

  • The length prefix is bounded at 256 MiB per record; larger records are rejected as implausible.

Differences from upstream#

  • Only reads the length-framed format written by pperl’s store_fd / nstore_fd. Upstream Storable’s fd format is not recognised. Pinned by t/81-xs-native/Storable/080-fd.t.

See also#

  • store_fd — matching writer (native order).

  • nstore_fd — matching writer (portable).

  • retrieve — read from a named path instead of a filehandle.

  • thaw — feed bytes you already have in memory.