Class: Krypt::Base64::Decoder
- Defined in:
- lib/krypt/codec/base64.rb
Overview
Base64-decodes any data written or read from it in the process.
Example: Reading and decoding Base64-encoded data from a file
f = File.open("b64", "rb")
b64 = Krypt::Base64::Decoder.new(f)
plain = b64.read # => result is decoded
b64.close
Example: Writing to a file while Base64-decoding the data
f = File.open("document", "wb")
b64 = Krypt::Base64::Decoder.new(f)
b64data = ... #some Base64-encoded data
b64 << b64data
b64.close # => contents in file will be decoded
Instance Method Summary collapse
- #close ⇒ Object
-
#read(len = nil) ⇒ Object
call-seq: in.read() -> String or nil.
-
#write(data) ⇒ Object
(also: #<<)
call-seq: out.write(string) -> Integer .
Methods included from Krypt::BaseCodec
#generic_read, #generic_write, #update_buffer
Methods inherited from IOFilter
Constructor Details
This class inherits a constructor from Krypt::IOFilter
Instance Method Details
#close ⇒ Object
134 135 136 137 |
# File 'lib/krypt/codec/base64.rb', line 134 def close generic_close super end |
#read(len = nil) ⇒ Object
call-seq:
in.read([len=nil]) -> String or nil
Reads from the underlying IO and Base64-decodes the data. Please see IO#read for further details. Note that in-place reading into a buffer is not supported.
117 118 119 120 |
# File 'lib/krypt/codec/base64.rb', line 117 def read(len=nil) read_len = len ? compute_decode_read_len(len) : nil generic_read(len, read_len) { |data| Krypt::Base64.decode(data) } end |
#write(data) ⇒ Object Also known as: <<
call-seq:
out.write(string) -> Integer
Base64-decodes string and writes it to the underlying IO. Please see IO#write for further details.
129 130 131 |
# File 'lib/krypt/codec/base64.rb', line 129 def write(data) generic_write(data, 4) { |data| Krypt::Base64.decode(data) } end |