eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'Base64Coder':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: Base64Coder


Inheritance:

   Object
   |
   +--Visitor
      |
      +--AspectVisitor
         |
         +--ObjectCoder
            |
            +--BaseNCoder
               |
               +--Base64Coder

Package:
stx:libbasic2
Category:
System-Storage
Version:
rev: 1.30 date: 2017/09/28 08:23:16
user: mawalch
file: Base64Coder.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
Stefan Vogel

Description:


Instances of this class perform Base64 en- and decoding as defined in RFC 2045
3 bytes are mapped to 4 characters, representing 6 bits each.
The encoded string consists only of characters from the set:
    'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='

The main entry point API is
    Base64Coder encode:aStringOrBytes
and
    Base64Coder decode:aString

If the decoder should return a string, use
    Base64Coder decodeAsString:aString.



[instance variables:]

[class variables:]
    Base64Mapping         String   Mapping from bytes (with 6 valid bits)
                                   to Base64 characters
    Base64ReverseMapping  Array    Mapping from Base64 characters to 6-bit-Bytes


Related information:



Class protocol:

initialization
o  initializeMappings
initialize class variables
usage example(s):
     self initializeMappings


Instance protocol:

encoding
o  nextPutByte: aByte
encode aByte on the output stream

misc
o  flush
flush the remaining bits of buffer.
The number of bits in buffer is not a multiple of 6, so we pad
the buffer and signal that padding has been done via $= characters.

private
o  fillBuffer
fill buffer with next 4 characters each representing 6 bits


Examples:


   (Base64Coder encode:'queen%27s%20gambit') asString = 'cXVlZW4lMjdzJTIwZ2FtYml0'
   (Base64Coder decode:'cXVlZW4lMjdzJTIwZ2FtYml0') asString = 'queen%27s%20gambit'
   |data1 text data2|

   data1 := #[0 1 16r7F 16r80 16r81 16rFE 16rFF].
   text := Base64Coder encode:data1.
   data2 := Base64Coder decode:text.
   data2
   |coder|

   coder := Base64Coder on:'' writeStream.
   coder nextPutAll:#[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19].
   coder flush.
   coder contents inspect.
   coder reset.
   coder nextPut:254.
   coder contents inspect.
   |coder decoder|

   coder := Base64Coder on:'' writeStream.
   coder nextPutAll:#[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20].
   coder flush.

   decoder := Base64Coder on:(coder contents readStream).
   [decoder atEnd] whileFalse:[
      Transcript show:decoder next
   ].
   Transcript cr.
   |coder|

   coder := Base64Coder on:'' writeStream.
   coder nextPutAll:(0 to:200) asByteArray.
   coder flush.

   Transcript showCR:(coder contents).


ST/X 7.1.0.0; WebServer 1.663 at exept.de:8081; Mon, 19 Nov 2018 22:34:50 GMT