7base64 Module
7.1Overview
The base64
module provides measures to decode/encode data formatted in base64 format.
To decode a stream that is formatted in base64, use one of the following functions:
base64.decode()
.. Reads base64 sequence from the given stream and returns a decoded data asbinary
. This is convenient when the data size is expected to be small.base64.reader()
.. Creates a stream that decodes base64 sequence from the given stream.stream#reader@base64()
method is another form of this function. You should use this way if the data size is expected to be large.
To encode a data into base64 format, use one of the following functions:
base64.encode()
.. Encodes the stream from the given stream and returns a encoded data asbinary
. This is convenient when the data size is expected to be small.base64.writer()
.. Creates a stream that encodes data fromwrite()
method into the given stream.stream#writer@base64()
method is another form of this function. You should use this way if the data size is expected to be large.
7.2Module Function
The base64
module provides following functions:
base64.decode(stream:stream:r) {block?}
Reads text stream that is formatted in base64 and returns the decoded result in binary.
If block
is specified, it would be evaluated with a block parameter |data:binary|
, where data
is the created instance. In this case, the block's result would become the function's returned value.
base64.encode(stream:stream:r, linelen:number:nil => 76) {block?}
Encodes content of the stream into base64 format and returns the result in binary.
If block
is specified, it would be evaluated with a block parameter |data:binary|
, where data
is the created instance. In this case, the block's result would become the function's returned value.
base64.reader(stream:stream:r) {block?}
Creates a stream instance that reads data formatted in base64 from stream
.
If block
is specified, it would be evaluated with a block parameter |s:stream|
, where s
is the created instance. In this case, the block's result would become the function's returned value.
base64.writer(stream:stream:w, linelen:number:nil => 76) {block?}
Creates a stream instance that encodes data to base64 format and writes it to the stream
.
The number of characters per line is specified by an argument linelen
. If omitted, that is 76.
If block
is specified, it would be evaluated with a block parameter |s:stream|
, where s
is the created instance. In this case, the block's result would become the function's returned value.
7.3Extension to stream Class
The base64
module extends the stream
class with following methods:
stream#reader@base64() {block?}
Creates a stream instance that reads data formatted in base64 from the target stream instance.
If block
is specified, it would be evaluated with a block parameter |s:stream|
, where s
is the created instance. In this case, the block's result would become the function's returned value.
stream#writer@base64(linelen:number:nil => 76) {block?}
Creates a stream instance that encodes data to base64 format and writes it to the target stream instance.
The number of characters per line is specified by an argument linelen
. If omitted, that is 76.
If block
is specified, it would be evaluated with a block parameter |s:stream|
, where s
is the created instance. In this case, the block's result would become the function's returned value.