module Kitchen::Base64Stream
Base64 encoder/decoder that operates on IO objects so as to minimize memory allocations on large payloads.
@author Fletcher Nichol <fnichol@nichol.ca>
Public Class Methods
strict_decode(io_in, io_out)
click to toggle source
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.
@param io_in [#read] input stream @param io_out [#write] output stream
# 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)
click to toggle source
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.
@param io_in [#read] input stream @param io_out [#write] output stream
# 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