read_magic#

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

תקציר#

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

מה מוחזר#

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.

דוגמאות#

Validate incoming bytes before committing to a thaw:

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

מקרי קצה#

  • 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.

הבדלים מן ה-upstream#

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

ראו גם#

  • file_magic - same inspection for a path on disk.

  • thaw - reconstruct the structure after validating magic.

  • freeze - producer whose output this inspects.