Module: Kitchen::Base64Stream
- Defined in:
- lib/kitchen/base64_stream.rb
Overview
Base64 encoder/decoder that operates on IO objects so as to minimize memory allocations on large payloads.
Class Method Summary collapse
-
.strict_decode(io_in, io_out) ⇒ Object
Decodes a Base64 input stream into an output stream.
-
.strict_encode(io_in, io_out) ⇒ Object
Encodes an input stream into a Base64 output stream.
Class Method Details
.strict_decode(io_in, io_out) ⇒ Object
Decodes a Base64 input stream into an output stream. The input and ouput objects must be opened IO resources. In other words, opening and closing the resources are not the responsibilty of this method.
42 43 44 45 46 |
# File 'lib/kitchen/base64_stream.rb', line 42 def self.strict_decode(io_in, io_out) buffer = "" io_out.write(buffer.unpack("m0").first) while io_in.read(3 * 1000, buffer) buffer = nil # rubocop:disable Lint/UselessAssignment end |
.strict_encode(io_in, io_out) ⇒ Object
Encodes an input stream into a Base64 output stream. The input and ouput objects must be opened IO resources. In other words, opening and closing the resources are not the responsibilty of this method.
30 31 32 33 34 |
# File 'lib/kitchen/base64_stream.rb', line 30 def self.strict_encode(io_in, io_out) buffer = "" io_out.write([buffer].pack("m0")) while io_in.read(3 * 1000, buffer) buffer = nil # rubocop:disable Lint/UselessAssignment end |