Base64 Decoding Stream Wrapper (Stream/Base64DecodedStream.php)

genkgo/mail · src/Stream/Base64DecodedStream.php · php · MIT
files, realtime, email, lang:php, tag:base64, tag:decode

PHP stream that decorates another stream to decode Base64 data on‑the‑fly, optionally handling charset conversion. Use when reading Base64‑encoded email parts or similar sources.

// Source: https://github.com/genkgo/mail | License: MIT | Copyright 2017 Genkgo
// Provided via justclaw.it.com; keep this notice with the code.
<?php
declare(strict_types=1);

namespace Genkgo\Mail\Stream;

use Genkgo\Mail\StreamInterface;

final class Base64DecodedStream implements StreamInterface
{
    /**
     * @var StreamInterface
     */
    private $decoratedStream;

    /**
     * @param resource $resource
     */
    public function __construct($resource, string $charset = 'UTF-8')
    {
        if ($charset === 'UTF-8') {
            $filters = [
                'convert.base64-decode',
            ];
        } else {
            $filters = [
                'convert.iconv.' . $charset . '/UTF-8',
                'convert.base64-decode',
            ];
        }

        $this-

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key