https://github.com/asmod4n/mruby-b64
Base64 for mruby with a streaming interface
https://github.com/asmod4n/mruby-b64
base64 mruby
Last synced: 3 months ago
JSON representation
Base64 for mruby with a streaming interface
- Host: GitHub
- URL: https://github.com/asmod4n/mruby-b64
- Owner: Asmod4n
- Created: 2016-05-07T21:01:31.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-07-03T20:15:39.000Z (over 9 years ago)
- Last Synced: 2025-01-11T18:47:28.134Z (about 1 year ago)
- Topics: base64, mruby
- Language: C
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mruby-b64
Examples
========
```ruby
#taken from https://en.wikipedia.org/wiki/Base64#Examples
plain = "Man is distinguished, not only by his reason, but by this singular passion from
other animals, which is a lust of the mind, that by a perseverance of delight
in the continued and indefatigable generation of knowledge, exceeds the short
vehemence of any carnal pleasure."
base64 = B64.encode(plain)
B64.decode(base64) == plain
```
Streaming Interface for encoding
```ruby
b64 = B64.new
b64 << "welcome " << "to " << "base64 " << "for " << "mruby"
base64 = b64.final
B64.decode(base64) == "welcome to base64 for mruby"
```
API for Streaming Decoding and Encoding
```ruby
encoder = B64::Encoder.new
step1 = encoder.encode "Man is distinguished, not only by his reason, but by this singular passion from\n"
step2 = encoder.encode "other animals, which is a lust of the mind, that by a perseverance of delight\n"
final = encoder.final
B64.decode(step1 + step2 + final) == "Man is distinguished, not only by his reason, but by this singular passion from\nother animals, which is a lust of the mind, that by a perseverance of delight\n"
```
```ruby
decoder = B64::Decoder.new
reverse_step1 = decoder.decode(step1)
reverse_step2_final = decoder.decode(step2 + final)
decoder.reset
"Man is distinguished, not only by his reason, but by this singular passion from\n" + "other animals, which is a lust of the mind, that by a perseverance of delight\n" == reverse_step1 + reverse_step2_final
```