Base64 In, Base64 Out
Your company archives scanned delivery notes with an external document service. Its REST API is strict about payloads: outgoing file bytes travel as a Base64 string inside a JSON field, and every response carries a Base64 string you must turn back into the original bytes. One stray line break — or one wrong padding character — and the archive rejects the request. You are building the codec that both directions run through; the HTTP plumbing is out of scope.
Requirements
Create a codeunit named "Base64 Document Codec" with two public procedures:
procedure EncodeDocument(var TempBlob: Codeunit "Temp Blob"): Text
procedure DecodeDocument(Base64Payload: Text; var TempBlob: Codeunit "Temp Blob")Rules:
EncodeDocumentreturns the standard Base64 encoding of the bytes stored inTempBlob, as a single line — no CR or LF characters anywhere, with=padding exactly where Base64 requires it.DecodeDocumentwrites the bytes encoded inBase64PayloadintoTempBlob— byte-perfect, so decoding whatEncodeDocumentproduced reproduces the original document exactly, byte count included.- An empty document encodes to an empty string, and decoding an empty payload leaves the document empty (zero bytes).
What the tests check
The grading tests write known ASCII content into a "Temp Blob" and compare your Base64 output character for character (the one-, two- and three-byte documents M, Ma and Man must become exactly TQ==, TWE= and TWFu — the three padding shapes). They decode known payloads and verify both the content and the exact byte count, check that a 300-byte document encodes to exactly 400 characters containing no CR or LF, and round-trip a randomly generated document through encode then decode expecting byte-for-byte equality. They also feed the codec raw binary bytes that are not valid text in both directions and expect the exact Base64 payload and the exact byte count back, and cover the empty-document and empty-payload cases.
Learn More
"Base64 Convert" has ToBase64/FromBase64 overloads that work directly on streams, and "Temp Blob" hands out CreateInStream/CreateOutStream over the bytes it holds.ToBase64 — the overload without the line-break option emits a single line. Decode: create an OutStream and let FromBase64 write the decoded bytes straight into it.