Helper class for base64 encoding/decoding and saving decoded content with sensible file extensions based on content type. Designed for backend use - no UI, no complex fluent API.
More...
|
| Base64Helper | WithInput (string base64String) |
| | Sets the base64 input string to work with. Returns this instance for simple chaining: WithInput(...).SaveTo(...).
|
| void | SaveTo (GPALFile filename) |
| | Saves the decoded bytes to the specified file path. Uses the suggested extension if the filename lacks one or has a generic one.
|
|
| static string | EncodeToBase64 (string text) |
| | Encodes a plain string to base64 using UTF-8 encoding.
|
| static string | DecodeFromBase64 (string base64String) |
| | Decodes a base64 string to UTF-8 text. Throws if the result is not valid UTF-8 or input is invalid base64.
|
| static string | GuessExtensionFromBytes (byte[] bytes) |
|
| string | SuggestedExtension [get] |
| | Returns the detected/suggested file extension for the decoded content. Useful for logging, UI hints, or constructing filenames.
|
Helper class for base64 encoding/decoding and saving decoded content with sensible file extensions based on content type. Designed for backend use - no UI, no complex fluent API.
Definition at line 29 of file Base64Helper.cs.
◆ DecodeFromBase64()
| string GenerallyPositive.Base64Helper.DecodeFromBase64 |
( |
string | base64String | ) |
|
|
static |
Decodes a base64 string to UTF-8 text. Throws if the result is not valid UTF-8 or input is invalid base64.
Definition at line 106 of file Base64Helper.cs.
◆ EncodeToBase64()
| string GenerallyPositive.Base64Helper.EncodeToBase64 |
( |
string | text | ) |
|
|
static |
Encodes a plain string to base64 using UTF-8 encoding.
Definition at line 95 of file Base64Helper.cs.
◆ GuessExtensionFromBytes()
| string GenerallyPositive.Base64Helper.GuessExtensionFromBytes |
( |
byte[] | bytes | ) |
|
|
static |
◆ SaveTo()
| void GenerallyPositive.Base64Helper.SaveTo |
( |
GPALFile | filename | ) |
|
Saves the decoded bytes to the specified file path. Uses the suggested extension if the filename lacks one or has a generic one.
- Parameters
-
| filename | Full path or filename to save to (e.g. "output.png", "C:\temp\doc.pdf") |
- Exceptions
-
| InvalidOperationException | If no input was set first |
| IOException | If file cannot be written |
Definition at line 74 of file Base64Helper.cs.
◆ WithInput()
| Base64Helper GenerallyPositive.Base64Helper.WithInput |
( |
string | base64String | ) |
|
Sets the base64 input string to work with. Returns this instance for simple chaining: WithInput(...).SaveTo(...).
- Parameters
-
| base64String | Base64-encoded data (may have whitespace) |
- Returns
- This instance
- Exceptions
-
| ArgumentException | If input is null/empty or invalid base64 |
Definition at line 43 of file Base64Helper.cs.
◆ SuggestedExtension
| string GenerallyPositive.Base64Helper.SuggestedExtension |
|
get |
Returns the detected/suggested file extension for the decoded content. Useful for logging, UI hints, or constructing filenames.
Definition at line 86 of file Base64Helper.cs.
The documentation for this class was generated from the following file: