|
Class: BaseNCoder
Object
|
+--Visitor
|
+--AspectVisitor
|
+--ObjectCoder
|
+--BaseNCoder
|
+--Base32Coder
|
+--Base64Coder
- Package:
- stx:libbasic2
- Category:
- System-Storage
- Version:
- rev:
1.11
date: 2017/02/10 10:15:52
- user: cg
- file: BaseNCoder.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
- Author:
- Stefan Vogel (stefan@zwerg)
Abstract superclass of Base64Coder and Base32Coder
Their main entry point API is
<BaseNCoder> encode:aStringOrBytes
and
<BaseNCoder> decode:aString
If the decoder should return a string, use
<BaseNCoder> decodeAsString:aString.
[examples:]
Base64Coder encode:'helloWorld'
Base64Coder decode:'aGVsbG9Xb3JsZA=='
Base64Coder decodeAsString:'aGVsbG9Xb3JsZA=='
[instance variables:]
buffer SmallInteger buffered data
bits SmallInteger Number of valid bits in buffer
charCount SmallInteger Number of characters since last cr
atEnd Boolean true if end of Base64 string reached
[class variables:]
decoding
-
decodeAsString: encodedString
-
decode a base-n encoded string.
We already expect a string instead of a ByteArray
initialization
-
initializeMappings
-
instance creation
-
new
-
queries
-
isAbstract
-
Return if this class is an abstract class.
True is returned here for myself only; false for subclasses.
Abstract subclasses must redefine this again.
accessing
-
lineLimit: something
-
set the line length of the encoded output.
Default is a line length of 76 characters.
If nil, no line breaks will be done.
decoding
-
next
-
answer the next decoded byte
-
next: count
-
return the next count bytes of the stream as ByteArray
-
peek
-
answer the next decoded byte. Do not consume this byte
encoding
-
visitByteArray: aByteArray with: aParameter
-
Base64Coder encodingOf:#[1 2 3 4 5 6 255]
-
visitObject: anObject with: aParameter
-
not defined. Use nextPut or nextPutAll:.
Could encode the printString here
-
visitStream: aStream with: aParameter
-
Base64Coder encodingOf:#[1 2 3 4 5 6 255]
Base64Coder encodingOf:#[1 2 3 4 5 6 255] readStream
-
visitString: aString with: aParameter
-
|encoded decoded decoder|
encoded := Base64Coder encode:'hello world'.
decoded := #[] writeStream.
decoder := Base64Coder on:encoded readStream.
[decoder atEnd] whileFalse:[
decoded nextPut:(decoder next).
].
decoded := decoded contents.
decoded asString.
initialization
-
emptyWriteStream
-
answer an empty stream. We encode as string
-
initialize
-
must be called if redefined
misc
-
reset
-
reset to initial state
private
-
basicNext
-
answer the next decoded byte.
No peekByte handling is done here.
queries
-
atEnd
-
answer true, if no more bytes can be read
-
binary
-
switch to binary mode - nothing is done here.
Defined for compatibility with ExternalStream.
-
isStream
-
we simulate a stream
stream compatibility
-
nextBytesInto: anObject startingAt: offset
-
copy bytes into anObject starting at offset
-
nextPut: aByte
-
encode aByte on the output stream
-
nextPutAll: aCollection startingAt: first to: last
-
append the elements with index from first to last
of the argument, aCollection onto the receiver.
-
nextPutBytes: aCollectionOfBytes
-
encode all objects from the argument
-
stringUpToEnd
-
return a collection of the elements up-to the end
-
upToEnd
-
return a collection of the elements up-to the end
subclass responsibility
-
fillBuffer
-
fill buffer with next n characters each representing m bits
** This method raises an error - it must be redefined in concrete classes **
-
flush
-
flush the remaining bits of buffer.
The number of bits in buffer is not a multiple of m, so we pad
the buffer and signal that padding has been done via $= characters.
** This method raises an error - it must be redefined in concrete classes **
-
nextPutByte: aByte
-
encode aByte on the output stream
** This method raises an error - it must be redefined in concrete classes **
|