34 lines
789 B
PHP
34 lines
789 B
PHP
<?php
|
|
// Base64.php
|
|
// Created: 2022-01-13
|
|
// Updated: 2023-07-21
|
|
|
|
namespace Index\Serialisation;
|
|
|
|
use Index\IO\Stream;
|
|
|
|
/**
|
|
* Provides a Base64 serialiser.
|
|
*/
|
|
final class Base64 {
|
|
/**
|
|
* Encodes binary data as a Base64 string.
|
|
*
|
|
* @param Stream|string $input Input binary data.
|
|
* @return string Base64 string representing the binary data.
|
|
*/
|
|
public static function encode(Stream|string $input): string {
|
|
return base64_encode((string)$input);
|
|
}
|
|
|
|
/**
|
|
* Decodes a Base64 string back to binary data.
|
|
*
|
|
* @param Stream|string $input Input Base64 string.
|
|
* @return string|false Binary data.
|
|
*/
|
|
public static function decode(Stream|string $input): string|bool {
|
|
return base64_decode((string)$input);
|
|
}
|
|
}
|