{
    "content": [
        {
            "type": "text",
            "text": "# MIME::Base64 (perldoc)\n\n## NAME\n\nMIME::Base64 - Encoding and decoding of base64 strings\n\n## SYNOPSIS\n\nuse MIME::Base64;\n$encoded = encodebase64('Aladdin:open sesame');\n$decoded = decodebase64($encoded);\n\n## DESCRIPTION\n\nThis module provides functions to encode and decode strings into and from the base64 encoding\nspecified in RFC 2045 - *MIME (Multipurpose Internet Mail Extensions)*. The base64 encoding is\ndesigned to represent arbitrary sequences of octets in a form that need not be humanly readable.\nA 65-character subset ([A-Za-z0-9+/=]) of US-ASCII is used, enabling 6 bits to be represented\nper printable character.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION** (8 subsections)\n- **EXAMPLES**\n- **COPYRIGHT**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "MIME::Base64",
        "section": "",
        "mode": "perldoc",
        "summary": "MIME::Base64 - Encoding and decoding of base64 strings",
        "synopsis": "use MIME::Base64;\n$encoded = encodebase64('Aladdin:open sesame');\n$decoded = decodebase64($encoded);",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [
            "If you want to encode a large file, you should encode it in chunks that are a multiple of 57",
            "bytes. This ensures that the base64 lines line up and that you do not end up with padding in the",
            "middle. 57 bytes of data fills one complete base64 line (76 == 57*4/3):",
            "use MIME::Base64 qw(encodebase64);",
            "open(FILE, \"/var/log/wtmp\") or die \"$!\";",
            "while (read(FILE, $buf, 60*57)) {",
            "print encodebase64($buf);",
            "or if you know you have enough memory",
            "use MIME::Base64 qw(encodebase64);",
            "local($/) = undef;  # slurp",
            "print encodebase64(<STDIN>);",
            "The same approach as a command line:",
            "perl -MMIME::Base64 -0777 -ne 'print encodebase64($)' <file",
            "Decoding does not need slurp mode if every line contains a multiple of four base64 chars:",
            "perl -MMIME::Base64 -ne 'print decodebase64($)' <file",
            "Perl v5.8 and better allow extended Unicode characters in strings. Such strings cannot be",
            "encoded directly, as the base64 encoding is only defined for single-byte characters. The",
            "solution is to use the Encode module to select the byte encoding you want. For example:",
            "use MIME::Base64 qw(encodebase64);",
            "use Encode qw(encode);",
            "$encoded = encodebase64(encode(\"UTF-8\", \"\\x{FFFF}\\n\"));",
            "print $encoded;"
        ],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 8,
                "subsections": [
                    {
                        "name": "encode_base64",
                        "lines": 1
                    },
                    {
                        "name": "encode_base64",
                        "lines": 10
                    },
                    {
                        "name": "decode_base64",
                        "lines": 14
                    },
                    {
                        "name": "encode_base64url",
                        "lines": 1
                    },
                    {
                        "name": "decode_base64url",
                        "lines": 5
                    },
                    {
                        "name": "encoded_base64_length",
                        "lines": 1
                    },
                    {
                        "name": "encoded_base64_length",
                        "lines": 3
                    },
                    {
                        "name": "decoded_base64_length",
                        "lines": 3
                    }
                ]
            },
            {
                "name": "EXAMPLES",
                "lines": 35,
                "subsections": []
            },
            {
                "name": "COPYRIGHT",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 4,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "MIME::Base64 - Encoding and decoding of base64 strings\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use MIME::Base64;\n\n$encoded = encodebase64('Aladdin:open sesame');\n$decoded = decodebase64($encoded);\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "This module provides functions to encode and decode strings into and from the base64 encoding\nspecified in RFC 2045 - *MIME (Multipurpose Internet Mail Extensions)*. The base64 encoding is\ndesigned to represent arbitrary sequences of octets in a form that need not be humanly readable.\nA 65-character subset ([A-Za-z0-9+/=]) of US-ASCII is used, enabling 6 bits to be represented\nper printable character.\n\nThe following primary functions are provided:\n",
                "subsections": [
                    {
                        "name": "encode_base64",
                        "content": ""
                    },
                    {
                        "name": "encode_base64",
                        "content": "Encode data by calling the encodebase64() function. The first argument is the byte string\nto encode. The second argument is the line-ending sequence to use. It is optional and\ndefaults to \"\\n\". The returned encoded string is broken into lines of no more than 76\ncharacters each and it will end with $eol unless it is empty. Pass an empty string as second\nargument if you do not want the encoded string to be broken into lines.\n\nThe function will croak with \"Wide character in subroutine entry\" if $bytes contains\ncharacters with code above 255. The base64 encoding is only defined for single-byte\ncharacters. Use the Encode module to select the byte encoding you want.\n"
                    },
                    {
                        "name": "decode_base64",
                        "content": "Decode a base64 string by calling the decodebase64() function. This function takes a single\nargument which is the string to decode and returns the decoded data.\n\nAny character not part of the 65-character base64 subset is silently ignored. Characters\noccurring after a '=' padding character are never decoded.\n\nIf you prefer not to import these routines into your namespace, you can call them as:\n\nuse MIME::Base64 ();\n$encoded = MIME::Base64::encode($decoded);\n$decoded = MIME::Base64::decode($encoded);\n\nAdditional functions not exported by default:\n"
                    },
                    {
                        "name": "encode_base64url",
                        "content": ""
                    },
                    {
                        "name": "decode_base64url",
                        "content": "Encode and decode according to the base64 scheme for \"URL applications\" [1]. This is a\nvariant of the base64 encoding which does not use padding, does not break the string into\nmultiple lines and use the characters \"-\" and \"\" instead of \"+\" and \"/\" to avoid using\nreserved URL characters.\n"
                    },
                    {
                        "name": "encoded_base64_length",
                        "content": ""
                    },
                    {
                        "name": "encoded_base64_length",
                        "content": "Returns the length that the encoded string would have without actually encoding it. This\nwill return the same value as \"length(encodebase64($bytes))\", but should be more efficient.\n"
                    },
                    {
                        "name": "decoded_base64_length",
                        "content": "Returns the length that the decoded string would have without actually decoding it. This\nwill return the same value as \"length(decodebase64($str))\", but should be more efficient.\n"
                    }
                ]
            },
            "EXAMPLES": {
                "content": "If you want to encode a large file, you should encode it in chunks that are a multiple of 57\nbytes. This ensures that the base64 lines line up and that you do not end up with padding in the\nmiddle. 57 bytes of data fills one complete base64 line (76 == 57*4/3):\n\nuse MIME::Base64 qw(encodebase64);\n\nopen(FILE, \"/var/log/wtmp\") or die \"$!\";\nwhile (read(FILE, $buf, 60*57)) {\nprint encodebase64($buf);\n}\n\nor if you know you have enough memory\n\nuse MIME::Base64 qw(encodebase64);\nlocal($/) = undef;  # slurp\nprint encodebase64(<STDIN>);\n\nThe same approach as a command line:\n\nperl -MMIME::Base64 -0777 -ne 'print encodebase64($)' <file\n\nDecoding does not need slurp mode if every line contains a multiple of four base64 chars:\n\nperl -MMIME::Base64 -ne 'print decodebase64($)' <file\n\nPerl v5.8 and better allow extended Unicode characters in strings. Such strings cannot be\nencoded directly, as the base64 encoding is only defined for single-byte characters. The\nsolution is to use the Encode module to select the byte encoding you want. For example:\n\nuse MIME::Base64 qw(encodebase64);\nuse Encode qw(encode);\n\n$encoded = encodebase64(encode(\"UTF-8\", \"\\x{FFFF}\\n\"));\nprint $encoded;\n",
                "subsections": []
            },
            "COPYRIGHT": {
                "content": "Copyright 1995-1999, 2001-2004, 2010 Gisle Aas.\n\nThis library is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n\nDistantly based on LWP::Base64 written by Martijn Koster <m.koster@nexor.co.uk> and Joerg\nReichelt <j.reichelt@nexor.co.uk> and code posted to comp.lang.perl\n<3pd2lp$6gf@wsinti07.win.tue.nl> by Hans Mulder <hansm@wsinti07.win.tue.nl>\n\nThe XS implementation uses code from metamail. Copyright 1991 Bell Communications Research, Inc.\n(Bellcore)\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "MIME::QuotedPrint\n\n[1] <http://en.wikipedia.org/wiki/Base64#URLapplications>\n",
                "subsections": []
            }
        }
    }
}