- README

- Top Level Namespace
- ArgumentError
- Array
- Atomic
- Base64
  - Error
- Benchmark
  - BM
    - Job
    - Tms
  - IPS
    - Entry
    - Job
- BigFloat
- BigInt
- BigRational
- BitArray
- Bool
- Box
- Bytes
- Channel
  - Buffered
  - ClosedError
  - ReceiveAction
  - SelectAction
  - SendAction
  - Unbuffered
- Char
  - Reader
- Class
- Colorize
  - Object
  - ObjectExtensions
- Comparable
- Complex
- Concurrent
  - CanceledError
- Crypto
  - Bcrypt
    - Error
    - Password
  - Blowfish
  - MD5
    - Context
  - Subtle
- CSV
  - Builder
    - Row
  - Error
  - Lexer
  - MalformedCSVError
  - Parser
  - Row
  - Token
    - Kind
- Debug
  - DWARF
    - LineNumbers
      - Register
      - Row
      - Sequence
    - LNE
    - LNS
  - ELF
    - Endianness
    - Error
    - Ident
    - Klass
    - Machine
    - OSABI
    - SectionHeader
      - Flags
      - Type
    - Type
- Deque
- Digest
  - SHA1
- Dir
- DivisionByZero
- DL
- ECR
- Enum
- Enumerable
  - EmptyError
- ENV
- Errno
- Exception
- Fiber
- File
  - Stat
- FileUtils
- Float
  - Primitive
- Float32
- Float64
- GC
  - Stats
- Hash
- HTML
- HTTP
  - Client
    - BodyType
    - Response
  - ComputedContentTypeHeader
  - Cookie
  - Cookies
  - DeflateHandler
  - ErrorHandler
  - Handler
    - Proc
  - Headers
  - LogHandler
  - Params
    - Builder
  - Request
  - Server
    - Context
    - RequestProcessor
    - Response
  - StaticFileHandler
    - DirectoryListing
  - WebSocket
  - WebSocketHandler
- Indexable
- IndexError
- INI
- Int
  - Primitive
  - Signed
  - Unsigned
- Int16
- Int32
- Int64
- Int8
- InvalidByteSequenceError
- IO
  - Buffered
  - ByteFormat
    - BigEndian
    - LittleEndian
    - NetworkEndian
    - SystemEndian
  - Delimited
  - EncodingOptions
  - EOFError
  - Error
  - FileDescriptor
  - Hexdump
  - Memory
  - MultiWriter
  - Seek
  - Sized
  - Timeout
- IPSocket
- Iterable
- Iterator
  - IteratorWrapper
  - Stop
- JSON
  - Any
  - ArrayBuilder
  - Builder
  - Error
  - Lexer
  - ObjectBuilder
  - ParseException
  - Parser
  - PrettyWriter
  - PullParser
  - Token
  - Type
- KeyError
- Levenshtein
  - Finder
- LLVM
  - ABI
    - AArch64
    - ArgKind
    - ArgType
    - ARM
    - FunctionType
    - X86
    - X86_64
      - RegClass
  - AtomicOrdering
  - AtomicRMWBinOp
  - Attribute
  - BasicBlock
  - BasicBlockCollection
  - Builder
  - CallConvention
  - CodeGenFileType
  - CodeGenOptLevel
  - CodeModel
  - Context
  - DIBuilder
  - DwarfTag
  - DwarfTypeEncoding
  - Function
  - FunctionCollection
  - FunctionPassManager
    - Runner
  - GenericValue
  - GlobalCollection
  - InstructionCollection
  - IntPredicate
  - JITCompiler
  - Linkage
  - MemoryBuffer
  - Module
  - ModulePassManager
  - ParameterCollection
  - PassManagerBuilder
  - PassRegistry
  - PhiTable
  - RealPredicate
  - RelocMode
  - Target
  - TargetData
  - TargetMachine
  - Type
    - Kind
  - Value
  - ValueMethods
  - VerifierFailureAction
- Logger
  - Formatter
  - Severity
- Markdown
  - HTMLRenderer
  - Parser
    - PrefixHeader
    - UnorderedList
  - Renderer
- Math
- MemoryIO
- Mutex
- NamedTuple
- Nil
- Number
  - Primitive
- OAuth
  - AccessToken
  - Consumer
  - Error
  - RequestToken
- OAuth2
  - AccessToken
    - Bearer
    - Mac
  - Client
  - Error
  - Session
- Object
- OpenSSL
  - Digest
    - Error
    - UnsupportedError
  - DigestBase
  - Error
  - HMAC
  - MD5
  - SHA1
  - SSL
    - Context
      - Client
      - Server
    - Error
    - ErrorType
    - Modes
    - Options
    - Socket
      - Client
      - Server
    - VerifyMode
    - X509VerifyFlags
  - X509
    - Certificate
    - Extension
    - Name
- OptionParser
  - Exception
  - InvalidOption
  - MissingOption
- PartialComparable
- Pointer
  - Appender
- PrettyPrint
- Proc
- Process
  - Env
  - Status
  - Stdio
  - Tms
- Random
  - MT19937
- Range
- Readline
  - CompletionProc
  - KeyBindingProc
- Reference
- Regex
  - MatchData
  - Options
- SecureRandom
- Set
- Signal
- Slice
- Socket
  - Address
  - Addrinfo
  - Error
  - Family
  - IPAddress
  - Protocol
  - Server
  - Type
  - UNIXAddress
- Spec
  - Expectations
  - Methods
  - ObjectExtensions
- StaticArray
- String
  - Builder
  - RawConverter
- StringPool
- StringScanner
- Struct
- Symbol
- System
- TCPServer
- TCPSocket
- Tempfile
- Termios
  - AttributeSelection
  - BaudRate
  - ControlMode
  - InputMode
  - LineControl
  - LocalMode
  - OutputMode
- Time
  - DayOfWeek
  - EpochConverter
  - EpochMillisConverter
  - Format
    - Error
  - Kind
  - MonthSpan
  - Span
- Tuple
- TypeCastError
- UDPSocket
- UInt16
- UInt32
- UInt64
- UInt8
- Unicode
  - CaseOptions
- Union
- UNIXServer
- UNIXSocket
- URI
  - Error
- Value
- XML
  - Attributes
  - AttributeType
  - Error
  - HTMLParserOptions
  - Namespace
  - Node
  - NodeSet
  - ParserOptions
  - Reader
  - SaveOptions
  - Type
  - XPathContext
- YAML
  - Any
  - Emitter
  - Error
  - EventKind
  - ParseException
  - Parser
  - PullParser
  - Type
- Zlib
  - Deflate
  - Error
  - Inflate

# module Base64

## Overview

The Base64 module provides for the encoding (`#encode`, `#strict_encode`, `#urlsafe_encode`) and decoding (`#decode`) of binary data using a Base64 representation.

### Example

A simple encoding and decoding.

    require "base64"
    enc   = Base64.encode("Send reinforcements")
                        # => "U2VuZCByZWluZm9yY2VtZW50cw==\n"
    plain = Base64.decode(enc)
                        # => "Send reinforcements"

The purpose of using base64 to encode data is that it translates any binary data into purely printable characters.

## Extended Modules

- Base64

## Defined in:

## Instance Method Summary

- #decode(data, io : IO)

  Write the Base64-decoded version of data to io.

- #decode(data) : Bytes

  Returns the Base64-decoded version of data as a `Bytes`.

- #decode_string(data) : String

  Returns the Base64-decoded version of data as a string.

- #encode(data, io : IO)

  Write the Base64-encoded version of data to io.

- #encode(data) : String

  Returns the Base64-encoded version of data.

- #strict_encode(data, io : IO)

  Write the Base64-encoded version of data with no newlines to io.

- #strict_encode(data) : String

  Returns the Base64-encoded version of data with no newlines.

- #urlsafe_encode(data, io : IO)

  Write the Base64-encoded version of data using a urlsafe alphabet to io.

- #urlsafe_encode(data, padding = true) : String

  Returns the Base64-encoded version of data using a urlsafe alphabet.

## Macro Summary

- next_decoded_value

  TODO uncomment if release 'private macro' private macro next_decoded_value :nodoc:

## Instance Method Detail

def decode(data, io : IO) #

Write the Base64-decoded version of data to io. This will decode either the normal or urlsafe alphabets.

def decode(data) : Bytes #

Returns the Base64-decoded version of data as a `Bytes`. This will decode either the normal or urlsafe alphabets.

def decode_string(data) : String #

Returns the Base64-decoded version of data as a string. If the data doesn't decode to a valid UTF8 string, InvalidByteSequenceError will be raised. This will decode either the normal or urlsafe alphabets.

def encode(data, io : IO) #

Write the Base64-encoded version of data to io. This method complies with RFC 2045. Line feeds are added to every 60 encoded characters.

    require "base64"
    Base64.encode("Now is the time for all good coders\nto learn Crystal", io)

def encode(data) : String #

Returns the Base64-encoded version of data. This method complies with RFC 2045. Line feeds are added to every 60 encoded characters.

    require "base64"
    puts Base64.encode("Now is the time for all good coders\nto learn Crystal")

Generates:

    Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g

def strict_encode(data, io : IO) #

Write the Base64-encoded version of data with no newlines to io. This method complies with RFC 4648.

    require "base64"
    Base64.strict_encode("Now is the time for all good coders\nto learn Crystal", io)

def strict_encode(data) : String #

Returns the Base64-encoded version of data with no newlines. This method complies with RFC 4648.

    require "base64"
    puts Base64.strict_encode("Now is the time for all good coders\nto learn Crystal")

Generates:

    Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4gQ3J5c3RhbA==

def urlsafe_encode(data, io : IO) #

Write the Base64-encoded version of data using a urlsafe alphabet to io. This method complies with "Base 64 Encoding with URL and Filename Safe Alphabet" in RFC 4648.

The alphabet uses '-' instead of '+' and '_' instead of '/'.

def urlsafe_encode(data, padding = true) : String #

Returns the Base64-encoded version of data using a urlsafe alphabet. This method complies with "Base 64 Encoding with URL and Filename Safe Alphabet" in RFC 4648.

The alphabet uses '-' instead of '+' and '_' instead of '/'.

The padding parameter defaults to true. When false, enough `=` characters are not added to make the output divisible by 4.

## Macro Detail

macro next_decoded_value #

TODO uncomment if release 'private macro' private macro next_decoded_value :nodoc: