Module: stdgo.encoding.base64
Overview
Package base64 implements base64 encoding as specified by RFC 4648.
Index
-
function benchmarkDecodeString(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkEncodeToString(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function benchmarkNewEncoding(_b:stdgo.Ref<stdgo.testing.B>):Void
-
function newEncoding(_encoder:stdgo.GoString):stdgo.Ref<stdgo.encoding.base64.Encoding>
-
function testDecodeBounds(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testDecodeCorrupt(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testDecodedLen(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testDecoderBuffering(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testDecoderIssue15656(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testDecoderIssue3577(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testDecoderIssue4779(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testDecoderIssue7733(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testDecoderRaw(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testEncodedLen(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testEncoderBuffering(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function testNewLineCharacters(_t:stdgo.Ref<stdgo.testing.T_>):Void
-
function decodeString( _s:stdgo.GoString):{ _1:stdgo.Error; _0:stdgo.Slice<stdgo.GoByte>;}
-
function encode( _dst:stdgo.Slice<stdgo.GoByte>, _src:stdgo.Slice<stdgo.GoByte>):Void
-
function encodeToString( _src:stdgo.Slice<stdgo.GoByte>):stdgo.GoString
-
function withPadding( _padding:stdgo.GoRune):stdgo.Ref<stdgo.encoding.base64.Encoding>
Examples
Constants
import stdgo.encoding.base64.Base64
final _decodeMapInitialize:stdgo.GoString = stdgo.Go.str(255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255)
final _encodeStd:stdgo.GoString = (("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" : stdgo.GoString))
final _encodeURL:stdgo.GoString = (("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" : stdgo.GoString))
final noPadding:stdgo.GoInt32 = ((-1 : stdgo.GoInt32))
No padding
final stdPadding:stdgo.GoInt32 = ((61 : stdgo.GoInt32))
Standard padding character
Variables
import stdgo.encoding.base64.Base64
var _bigtest:stdgo.encoding.base64.T_testpair
var _encodingTests:stdgo.Slice<stdgo.encoding.base64.T_encodingTest>
var _funnyEncoding:stdgo.Ref<stdgo.encoding.base64.Encoding>
A nonstandard encoding with a funny padding character, for testing
var _pairs:stdgo.Slice<stdgo.encoding.base64.T_testpair>
var rawStdEncoding:stdgo.Ref<stdgo.encoding.base64.Encoding>
RawStdEncoding is the standard raw, unpadded base64 encoding, as defined in RFC 4648 section 3.2. This is the same as StdEncoding but omits padding characters.
var rawURLEncoding:stdgo.Ref<stdgo.encoding.base64.Encoding>
RawURLEncoding is the unpadded alternate base64 encoding defined in RFC 4648. It is typically used in URLs and file names. This is the same as URLEncoding but omits padding characters.
var stdEncoding:stdgo.Ref<stdgo.encoding.base64.Encoding>
StdEncoding is the standard base64 encoding, as defined in RFC 4648.
var urlencoding:stdgo.Ref<stdgo.encoding.base64.Encoding>
URLEncoding is the alternate base64 encoding defined in RFC 4648. It is typically used in URLs and file names.
Functions
import stdgo.encoding.base64.Base64
function _assemble32
function _assemble32(_n1:stdgo.GoByte, _n2:stdgo.GoByte, _n3:stdgo.GoByte, _n4:stdgo.GoByte):{
_1:Bool;
_0:stdgo.GoUInt32;
}
assemble32 assembles 4 base64 digits into 3 bytes. Each digit comes from the decode map, and will be 0xff if it came from an invalid character.
function _assemble64
function _assemble64(_n1:stdgo.GoByte, _n2:stdgo.GoByte, _n3:stdgo.GoByte, _n4:stdgo.GoByte, _n5:stdgo.GoByte, _n6:stdgo.GoByte, _n7:stdgo.GoByte, _n8:stdgo.GoByte):{
_1:Bool;
_0:stdgo.GoUInt64;
}
assemble64 assembles 8 base64 digits into 6 bytes. Each digit comes from the decode map, and will be 0xff if it came from an invalid character.
function _funnyRef
function _funnyRef(_ref:stdgo.GoString):stdgo.GoString
function _rawRef
function _rawRef(_ref:stdgo.GoString):stdgo.GoString
Convert a reference string to raw, unpadded format
function _rawURLRef
function _rawURLRef(_ref:stdgo.GoString):stdgo.GoString
Both URL and unpadding conversions
function _stdRef
function _stdRef(_ref:stdgo.GoString):stdgo.GoString
Do nothing to a reference base64 string (leave in standard format)
function _testEqual
function _testEqual(_t:stdgo.Ref<stdgo.testing.T_>, _msg:stdgo.GoString, _args:haxe.Rest<stdgo.AnyInterface>):Bool
function _urlRef
function _urlRef(_ref:stdgo.GoString):stdgo.GoString
Convert a reference string to URL-encoding
function benchmarkDecodeString
function benchmarkDecodeString(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkEncodeToString
function benchmarkEncodeToString(_b:stdgo.Ref<stdgo.testing.B>):Void
function benchmarkNewEncoding
function benchmarkNewEncoding(_b:stdgo.Ref<stdgo.testing.B>):Void
function newDecoder
function newDecoder(_enc:stdgo.Ref<stdgo.encoding.base64.Encoding>, _r:stdgo.io.Reader):stdgo.io.Reader
NewDecoder constructs a new base64 stream decoder.
function newEncoder
function newEncoder(_enc:stdgo.Ref<stdgo.encoding.base64.Encoding>, _w:stdgo.io.Writer):stdgo.io.WriteCloser
NewEncoder returns a new base64 stream encoder. Data written to the returned writer will be encoded using enc and then written to w. Base64 encodings operate in 4-byte blocks; when finished writing, the caller must Close the returned encoder to flush any partially written blocks.
exampleNewEncoder
function exampleNewEncoder():Void {
var _input = (stdgo.Go.str("foo", 0, "bar") : stdgo.Slice<stdgo.GoByte>);
var _encoder:stdgo.io.Io.WriteCloser = stdgo.encoding.base64.Base64.newEncoder(stdgo.encoding.base64.Base64.stdEncoding, stdgo.Go.asInterface(stdgo.os.Os.stdout));
_encoder.write(_input);
_encoder.close();
}
function newEncoding
function newEncoding(_encoder:stdgo.GoString):stdgo.Ref<stdgo.encoding.base64.Encoding>
NewEncoding returns a new padded Encoding defined by the given alphabet, which must be a 64-byte string that does not contain the padding character or CR / LF ('\r', '\n'). The alphabet is treated as sequence of byte values without any special treatment for multi-byte UTF-8. The resulting Encoding uses the default padding character ('='), which may be changed or disabled via WithPadding.
function testBig
function testBig(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testDecode
function testDecode(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testDecodeBounds
function testDecodeBounds(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testDecodeCorrupt
function testDecodeCorrupt(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testDecodedLen
function testDecodedLen(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testDecoder
function testDecoder(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testDecoderBuffering
function testDecoderBuffering(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testDecoderIssue15656
function testDecoderIssue15656(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testDecoderIssue3577
function testDecoderIssue3577(_t:stdgo.Ref<stdgo.testing.T_>):Void
tests that we don't ignore errors from our underlying reader
function testDecoderIssue4779
function testDecoderIssue4779(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testDecoderIssue7733
function testDecoderIssue7733(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testDecoderRaw
function testDecoderRaw(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testEncode
function testEncode(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testEncodedLen
function testEncodedLen(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testEncoder
function testEncoder(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testEncoderBuffering
function testEncoderBuffering(_t:stdgo.Ref<stdgo.testing.T_>):Void
function testNewLineCharacters
function testNewLineCharacters(_t:stdgo.Ref<stdgo.testing.T_>):Void
Classes
import stdgo.encoding.base64.*
class Encoding
An Encoding is a radix 64 encoding/decoding scheme, defined by a 64-character alphabet. The most common encoding is the "base64" encoding defined in RFC 4648 and used in MIME (RFC 2045) and PEM (RFC 1421). RFC 4648 also defines an alternate encoding, which is the standard encoding with - and _ substituted for + and /.
var _decodeMap:stdgo.GoArray<stdgo.GoUInt8>
var _encode:stdgo.GoArray<stdgo.GoUInt8>
var _padChar:stdgo.GoInt32
var _strict:Bool
Encoding function new
function new(?_encode:stdgo.GoArray<stdgo.GoUInt8>, ?_decodeMap:stdgo.GoArray<stdgo.GoUInt8>, ?_padChar:stdgo.GoInt32, ?_strict:Bool):Void
Encoding function _decodeQuantum
function _decodeQuantum( _dst:stdgo.Slice<stdgo.GoByte>, _src:stdgo.Slice<stdgo.GoByte>, _si:stdgo.GoInt):{
_2:stdgo.Error;
_1:stdgo.GoInt;
_0:stdgo.GoInt;
}
decodeQuantum decodes up to 4 base64 bytes. The received parameters are the destination buffer dst, the source buffer src and an index in the source buffer si. It returns the number of bytes read from src, the number of bytes written to dst, and an error, if any.
Encoding function decode
function decode( _dst:stdgo.Slice<stdgo.GoByte>, _src:stdgo.Slice<stdgo.GoByte>):{
_1:stdgo.Error;
_0:stdgo.GoInt;
}
Decode decodes src using the encoding enc. It writes at most DecodedLen(len(src)) bytes to dst and returns the number of bytes written. If src contains invalid base64 data, it will return the number of bytes successfully written and CorruptInputError. New line characters (\r and \n) are ignored.
Encoding function decodeString
function decodeString( _s:stdgo.GoString):{
_1:stdgo.Error;
_0:stdgo.Slice<stdgo.GoByte>;
}
DecodeString returns the bytes represented by the base64 string s.
Encoding function decodedLen
function decodedLen( _n:stdgo.GoInt):stdgo.GoInt
DecodedLen returns the maximum length in bytes of the decoded data corresponding to n bytes of base64-encoded data.
Encoding function encode
function encode( _dst:stdgo.Slice<stdgo.GoByte>, _src:stdgo.Slice<stdgo.GoByte>):Void
Encode encodes src using the encoding enc, writing EncodedLen(len(src)) bytes to dst.
The encoding pads the output to a multiple of 4 bytes, so Encode is not appropriate for use on individual blocks of a large data stream. Use NewEncoder() instead.
Encoding function encodeToString
function encodeToString( _src:stdgo.Slice<stdgo.GoByte>):stdgo.GoString
EncodeToString returns the base64 encoding of src.
Encoding function encodedLen
function encodedLen( _n:stdgo.GoInt):stdgo.GoInt
EncodedLen returns the length in bytes of the base64 encoding of an input buffer of length n.
Encoding function strict
function strict():stdgo.Ref<stdgo.encoding.base64.Encoding>
Strict creates a new encoding identical to enc except with strict decoding enabled. In this mode, the decoder requires that trailing padding bits are zero, as described in RFC 4648 section 3.5.
Note that the input is still malleable, as new line characters (CR and LF) are still ignored.
Encoding function withPadding
function withPadding( _padding:stdgo.GoRune):stdgo.Ref<stdgo.encoding.base64.Encoding>
WithPadding creates a new encoding identical to enc except with a specified padding character, or NoPadding to disable padding. The padding character must not be '\r' or '\n', must not be contained in the encoding's alphabet and must be a rune equal or below '\xff'. Padding characters above '\x7f' are encoded as their exact byte value rather than using the UTF-8 representation of the codepoint.
Typedefs
import stdgo.encoding.base64.*
typedef CorruptInputError
typedef CorruptInputError = stdgo.GoInt64;
typedef T__struct_0
typedef T__struct_0 = {
_offset:stdgo.GoInt;
_input:stdgo.GoString;
};
typedef T__struct_1
typedef T__struct_1 = {
_want:stdgo.GoInt;
_n:stdgo.GoInt;
_enc:stdgo.Ref<stdgo.encoding.base64.Encoding>;
};