Encoding / Decoding Base64 format.
Implemented according to RFC 4648 - The Base16.
ubyte[] data = [0x14, 0xfb, 0x9c, 0x03, 0xd9, 0x7e]; const(char)[] encoded = Base64.encode(data); assert(encoded == "FPucA9l+"); ubyte[] decoded = Base64.decode("FPucA9l+"); assert(decoded == [0x14, 0xfb, 0x9c, 0x03, 0xd9, 0x7e]);
// Create MIME Base64 with CRLF, per line 76. File f = File("./text.txt", "r"); scope(exit) f.close(); Appender!string mime64 = appender!string; foreach (encoded; Base64.encoder(f.byChunk(57))) { mime64.put(encoded); mime64.put("\r\n"); } writeln(mime64.data);
The Base64
The "URL and Filename safe" Base64
Core implementation for Base64 format.
alias Base64Impl!('+', '/') Base64; // The Base64 format(Already defined). alias Base64Impl!('!', '=', Base64.NoPadding) Base64Re; // non-standard Base64 format for Regular expression
Calculates the minimum length for encoding.
size_t sourceLength | the length of source array. |
Encodes source into buffer.
R1 source | an InputRange to encode. |
R2 buffer | a buffer to store encoded result. |
Encodes source into range.
R1 source | an InputRange to encode. |
R2 range | an OutputRange to put encoded result. |
Encodes source to new buffer.
Shortcut to encode(source, buffer) function.
Range that encodes chunk data at a time.
Range primitive operation that checks iteration state.
Range primitive operation that returns the currently iterated element.
Range primitive operation that advances the range to its next element.
Captures a Range state.
Range that encodes single character at a time.
Range primitive operation that checks iteration state.
Range primitive operation that returns the currently iterated element.
Range primitive operation that advances the range to its next element.
Captures a Range state.
Iterates through an InputRange at a time by using Encoder.
Default Encoder encodes chunk data.
File f = File("text.txt", "r"); scope(exit) f.close(); uint line = 0; foreach (encoded; Base64.encoder(f.byLine())) { writeln(++line, ". ", encoded); }
ubyte[] data = cast(ubyte[]) "0123456789"; // The ElementType of data is not aggregation type foreach (encoded; Base64.encoder(data)) { writeln(encoded); }
Range range | an InputRange to iterate. |
Calculates the minimum length for decoding.
size_t sourceLength | the length of source array. |
Decodes source into buffer.
R1 source | an InputRange to decode. |
R2 buffer | a buffer to store decoded result. |
Decodes source into range.
R1 source | an InputRange to decode. |
R2 range | an OutputRange to put decoded result |
Decodes source into new buffer.
Shortcut to decode(source, buffer) function.
Range that decodes chunk data at a time.
Range primitive operation that checks iteration state.
Range primitive operation that returns the currently iterated element.
Range primitive operation that advances the range to its next element.
Captures a Range state.
Range that decodes single character at a time.
Range primitive operation that checks iteration state.
Range primitive operation that returns the currently iterated element.
Range primitive operation that advances the range to its next element.
Captures a Range state.
Iterates through an InputRange at a time by using Decoder.
Default Decoder decodes chunk data.
foreach (decoded; Base64.decoder(stdin.byLine()))
{
writeln(decoded);
}
auto encoded = Base64.encoder(cast(ubyte[])"0123456789"); foreach (n; map!q{a - '0'}(Base64.decoder(encoded))) { writeln(n); }
Range range | an InputRange to iterate. |
Exception thrown on Base64 errors.