License:
BSD style: see license.txt

author:
Jeff Davey

Standards:
rfc3548, rfc2045

Since:
0.99.7







This module is used to decode and encode base64 char[] arrays.

Example:
    char[] blah = "Hello there, my name is Jeff.";
    scope encodebuf = new char[allocateEncodeSize(cast(ubyte[])blah)];
    char[] encoded = encode(cast(ubyte[])blah, encodebuf);

    scope decodebuf = new ubyte[encoded.length];
    if (cast(char[])decode(encoded, decodebuf) == "Hello there, my name is Jeff.")
        Stdout("yay").newline;


  • uint allocateEncodeSize (ubyte[] data);
  • calculates and returns the size needed to encode the length of the array passed.

    Params:
    ubyte[] data An array that will be encoded

  • uint allocateEncodeSize (uint length);
  • calculates and returns the size needed to encode the length passed.

    Params:
    uint length Number of bytes to be encoded

  • int encodeChunk (ubyte[] data, char[] buff, ref int bytesEncoded);
  • encodes data into buff and returns the number of bytes encoded. this will not terminate and pad any "leftover" bytes, and will instead only encode up to the highest number of bytes divisible by three.

    returns the number of bytes left to encode

    Params:
    ubyte[] data what is to be encoded
    char[] buff buffer large enough to hold encoded data
    int bytesEncoded inout that returns how much of the buffer was filled

  • char[] encode (ubyte[] data, char[] buff);
  • encodes data and returns as an ASCII base64 string.

    Params:
    ubyte[] data what is to be encoded
    char[] buff buffer large enough to hold encoded data

    Example:
        char[512] encodebuf;
        char[] myEncodedString = encode(cast(ubyte[])"Hello, how are you today?", encodebuf);
        Stdout(myEncodedString).newline; // SGVsbG8sIGhvdyBhcmUgeW91IHRvZGF5Pw==
    


  • char[] encode (ubyte[] data);
  • encodes data and returns as an ASCII base64 string.

    Params:
    ubyte[] data what is to be encoded

    Example:
        char[] myEncodedString = encode(cast(ubyte[])"Hello, how are you today?");
        Stdout(myEncodedString).newline; // SGVsbG8sIGhvdyBhcmUgeW91IHRvZGF5Pw==
    


  • ubyte[] decode (char[] data);
  • decodes an ASCCI base64 string and returns it as ubyte[] data. Pre-allocates the size of the array.

    This decoder will ignore non-base64 characters. So: SGVsbG8sIGhvd yBhcmUgeW91IH RvZGF5Pw==

    Is valid.


    Params:
    char[] data what is to be decoded

    Example:
        char[] myDecodedString = cast(char[])decode("SGVsbG8sIGhvdyBhcmUgeW91IHRvZGF5Pw==");
        Stdout(myDecodeString).newline; // Hello, how are you today?
    


  • ubyte[] decode (char[] data, ubyte[] buff);
  • decodes an ASCCI base64 string and returns it as ubyte[] data.

    This decoder will ignore non-base64 characters. So: SGVsbG8sIGhvd yBhcmUgeW91IH RvZGF5Pw==

    Is valid.


    Params:
    char[] data what is to be decoded
    ubyte[] buff a big enough array to hold the decoded data

    Example:
        ubyte[512] decodebuf;
        char[] myDecodedString = cast(char[])decode("SGVsbG8sIGhvdyBhcmUgeW91IHRvZGF5Pw==", decodebuf);
        Stdout(myDecodeString).newline; // Hello, how are you today?
    


    Copyright (c) 2008 Jeff Davey. All rights reserved :: page rendered by CandyDoc