logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Data::Printer::Filter::ContentType - detect popular (binary) content in strings

Description

       This is a filter plugin for Data::Printer that looks for binary strings with signatures from popular file
       types. If one is detected, instead of the bogus binary dump it will print the content type and the string
       size.

       For example, let's say you've read an image file into $data, maybe from a user upload or from Imager or
       ImageMagick. If you use Data::Printer with this filter, it will show you something like this:

           my $data = get_image_content_from_somewhere();

           use DDP; p $data;   # (PNG Image, 32K)

   hexdump
       If, for whatever reason, you want to inspect the actual content of the binary data, you may set
       "filter_contenttype.hexdump" to true. This will pretty-print your data in hexadecimal, similar to tools
       like "hexdump". Once active, it will print the entire content, but you may limit the size by changing
       "filter_contenttype.hexdump_size" to any value (unit == bytes), and you can even start from a different
       position using "filter_contenttype.hexdump_offset". Set it to a negative value to make your offset
       relative to the end to the data.

       Finally, the default hexdump mode will not indent your content. Since it's a binary dump, we want to get
       as much terminal space as we can. If you rather have the dump properly indented (relative to your current
       dump indentation level), just set "filter_contenttype.hexdump_indent" to 1.

   DetectedContent
       Below are the signatures detected by this filter.

       Images

       •   PNG

       •   JPEG

       •   GIF

       •   ICO

       •   TIFF

       •   BMP

       Video

       •   AVI

       •   MPEG

       Audio

       •   WAV

       •   MP3

       •   FLAC

       •   OGG

       DocumentsandArchives

       •   ZIP

       •   GZIP

       •   BZIP2

       •   PDF

       •   Binary Executables (ELF and Win32)

       We  don't  want  this  list  to grow into a full-blown detection system, and instead just focus on common
       types. So if you want to contribute with patches or open an issue for a missing type,  please  make  sure
       you  actuallyhavedatastructureswiththatcontent (e.g. you were bit by this in your code and DDP
       didn't help).

       We want to help people debug code, not add content types just for the sake of it :)

Name

       Data::Printer::Filter::ContentType - detect popular (binary) content in strings

See Also

       Data::Printer

perl v5.38.2                                       2024-04-27             Data::Printer::...er::ContentType(3pm)

Synopsis

       In your ".dataprinter" file:

           filters = ContentType

       You may also customize the look and feel with the following options (defaults shown):

           filter_contenttype.show_size = 1
           filter_contenttype.size_unit = auto

           # play around with these if you want to print the binary content:
           filter_contenttype.hexdump        = 0
           filter_contenttype.hexdump_size   = 0
           filter_contenttype.hexdump_offset = 0
           filter_contenttype.hexdump_indent = 0

           # you can even customize your themes:
           colors.filter_contenttype         = #ca88dd
           colors.filter_contenttype_hexdump = #ffcb68

       That's it!

See Also