Parse::Binary(3pm)
β¨ Parse::Binary β¨
okay bestie, gather round, because this is Parse::Binary, a Perl module (yes, the (3pm) kind, we're in manpage territory π
) and it's genuinely one of those "wait this is so smart" situations. It unpacks binary data structures into object hierarchies. iconic behavior tbh.
πΈ VERSION πΈ
This doc describes version 0.11 of Parse::Binary, released January 25, 2009. vintage! retro! a little elder-millennial but we respect it π«Ά
π SYNOPSIS π
okay so first up, this class represents a Win32 .ico file:
package IconFile;
use base 'Parse::Binary';
use constant FORMAT => (
Magic => 'a2',
Type => 'v',
Count => 'v',
'Icon' => [ 'a16', '{$Count}', 1 ],
Data => 'a*',
);
and this one is a single icon resource, like the little guy inside:
package Icon;
use base 'Parse::Binary';
use constant FORMAT => (
Width => 'C',
Height => 'C',
ColorCount => 'C',
Reserved => 'C',
Planes => 'v',
BitCount => 'v',
ImageSize => 'V',
ImageOffset => 'v',
);
sub Data {
my ($self) = @_;
return $self->parent->substr($self->ImageOffset, $self->ImageSize);
}
and here's a simple little .ico dumper that uses both of them, because of course:
use IconFile;
my $icon_file = IconFile->new('input.ico');
foreach my $icon ($icon_file->members) {
print "Dimension: ", $icon->Width, "x", $icon->Height, $/;
print "Colors: ", 2 ** $icon->BitCount, $/;
print "Image Size: ", $icon->ImageSize, " bytes", $/;
print "Actual Size: ", length($icon->Data), " bytes", $/, $/;
}
$icon_file->write('output.ico'); # save as another .ico file
like. it reads the file, prints the stats, and writes it back out. main character energy fr fr π
π¦ DESCRIPTION π¦
So the whole point of this module is that parsing binary data structures gets so much easier. It works by being a base class for classes that represent the binary data β and those classes can contain objects of other classes to represent parts of themselves. it's giving nesting dolls but make it bytes π
ngl, the documentation is unfortunately a bit lacking at this moment π that's literally what the original says, not me being dramatic.
If you want actual examples of how to use this thing, go read the tests and the source code of Parse::AFP and Win32::Exe. that's where the real ones learn. iykyk β¨
π AUTHORS π
Audrey Tang <cpan@audreyt.org> β legend behavior, no cap π«Ά
π COPYRIGHT π
Copyright 2004-2009 by Audrey Tang <cpan@audreyt.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See <http://www.perl.com/perl/misc/Artistic.html>
π one last thing bestie π
This page ships with perl v5.36.0, dated 2022-12-04. yeah the module is from 2009 and the manpage footer is from 2022, we love a timeless queen π go parse something. periodt. ππ¦β¨
π¦ where this page comes from
- debian bookworm: libparse-binary-perl 0.11-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libparse-binary-perl 0.11-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libparse-binary-perl 0.11-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libparse-binary-perl 0.11-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libparse-binary-perl 0.11-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms