View source code
Display the source code in std/base64.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

std.base64.Base64Impl.decode - multiple declarations

Function Base64Impl.decode

Decodes source into the given buffer.

ubyte[] decode(R1, R2) (
  in R1 source,
  R2 buffer
) pure @trusted
if (isArray!R1 && is(ElementType!R1 : dchar) && is(R2 == ubyte[]) && isOutputRange!(R2, ubyte));

ubyte[] decode(R1, R2) (
  R1 source,
  R2 buffer
)
if (!isArray!R1 && isInputRange!R1 && is(ElementType!R1 : dchar) && hasLength!R1 && is(R2 == ubyte[]) && isOutputRange!(R2, ubyte));

Parameters

NameDescription
source The input range to decode.
buffer The buffer to store decoded result.

Returns

The slice of buffer containing the decoded result.

Throws

Base64Exception if source contains characters outside the base alphabet of the current Base64 encoding scheme.

Example

auto encoded = "Gis8TV1u";
ubyte[32] buffer;   // much bigger than necessary

// Just to be sure...
auto decodedLength = Base64.decodeLength(encoded.length);
assert(buffer.length >= decodedLength);

// decode() returns a slice of the given buffer.
auto decoded = Base64.decode(encoded, buffer[]);
assert(decoded is buffer[0 .. decodedLength]);
writeln(decoded); // [0x1a, 0x2b, 0x3c, 0x4d, 0x5d, 0x6e]

Function Base64Impl.decode

Decodes source into a given output range.

size_t decode(R1, R2) (
  in R1 source,
  auto ref R2 range
)
if (isArray!R1 && is(ElementType!R1 : dchar) && !is(R2 == ubyte[]) && isOutputRange!(R2, ubyte));

size_t decode(R1, R2) (
  R1 source,
  auto ref R2 range
)
if (!isArray!R1 && isInputRange!R1 && is(ElementType!R1 : dchar) && hasLength!R1 && !is(R2 == ubyte[]) && isOutputRange!(R2, ubyte));

Parameters

NameDescription
source The input range to decode.
range The output range to store the decoded result.

Returns

The number of times the output range's put method was invoked.

Throws

Base64Exception if source contains characters outside the base alphabet of the current Base64 encoding scheme.

Example

struct OutputRange
{
    ubyte[] result;
    void put(ubyte b) { result ~= b; }
}
OutputRange output;

// This overload of decode() returns the number of calls to put().
writeln(Base64.decode("Gis8TV1u", output)); // 6
writeln(output.result); // [0x1a, 0x2b, 0x3c, 0x4d, 0x5d, 0x6e]

Function Base64Impl.decode

Decodes source into newly-allocated buffer.

ubyte[] decode(Range) (
  Range source
) pure @safe
if (isArray!Range && is(ElementType!Range : dchar));

ubyte[] decode(Range) (
  Range source
)
if (!isArray!Range && isInputRange!Range && is(ElementType!Range : dchar) && hasLength!Range);

This convenience method alleviates the need to manually manage decoding buffers.

Parameters

NameDescription
source The input range to decode.

Returns

A newly-allocated ubyte[] buffer containing the decoded string.

Example

auto data = "Gis8TV1u";
writeln(Base64.decode(data)); // [0x1a, 0x2b, 0x3c, 0x4d, 0x5d, 0x6e]

Authors

Masahiro Nakagawa, Daniel Murphy (Single value Encoder and Decoder)

License

Boost License 1.0.