read_magic#

Inspect an in-memory frozen buffer’s header, returning metadata as a hash reference.

Synopsis#

use Storable qw(read_magic);
my $info = read_magic($bytes);
die "not Storable" unless $info;

What you get back#

A hash reference describing the payload’s header, or undef if $bytes does not begin with a valid Storable tag. Keys match those of file_magic, minus file (there is no path to report): netorder, major, minor, hdrsize.

Examples#

Validate incoming bytes before committing to a thaw:

my $info = read_magic($received);
die "bad input" unless $info;
my $data = thaw($received);

Edge cases#

  • Returns undef for an empty string or any buffer whose first meaningful byte is not a known tag.

  • Only the header is inspected; the rest of $bytes is not scanned.

Differences from upstream#

  • See file_magic — the same key subset is returned. Pinned by t/81-xs-native/Storable/200-file-magic.t.

See also#

  • file_magic — same inspection for a path on disk.

  • thaw — reconstruct the structure after validating magic.

  • freeze — producer whose output this inspects.