Class: Worochi::Agent::Github::Helper::Base64IO
- Inherits:
-
Object
- Object
- Worochi::Agent::Github::Helper::Base64IO
- Defined in:
- lib/worochi/helper/github_helper.rb
Overview
This is a wrapper around the file content that streams the file as a Base64 encoded string.
Instance Method Summary collapse
-
#eof? ⇒ Boolean
File has been fully read.
-
#initialize(file) ⇒ Base64IO
constructor
A new instance of Base64IO.
- #read(length = size, outbuf = nil) ⇒ String
-
#rewind ⇒ Object
Rewind the stream.
-
#size ⇒ Integer
Size of the JSON.
Constructor Details
#initialize(file) ⇒ Base64IO
Returns a new instance of Base64IO.
75 76 77 78 79 80 |
# File 'lib/worochi/helper/github_helper.rb', line 75 def initialize(file) file.rewind @file = file @encoded_size = (@file.size / 3.0).ceil * 4 @buffer = '' end |
Instance Method Details
#eof? ⇒ Boolean
Returns file has been fully read.
88 89 90 |
# File 'lib/worochi/helper/github_helper.rb', line 88 def eof? @buffer.empty? && @file.eof? end |
#read(length = size, outbuf = nil) ⇒ String
102 103 104 105 106 107 |
# File 'lib/worochi/helper/github_helper.rb', line 102 def read(length=size, outbuf=nil) while @buffer.length < length and not @file.eof? @buffer += Base64.strict_encode64 @file.read(BLOCK_SIZE) end @buffer.empty? ? nil : @buffer.slice!(0, length) end |
#rewind ⇒ Object
Rewind the stream.
93 94 95 96 97 |
# File 'lib/worochi/helper/github_helper.rb', line 93 def rewind @file.rewind @buffer = '' nil end |
#size ⇒ Integer
Returns size of the JSON.
83 84 85 |
# File 'lib/worochi/helper/github_helper.rb', line 83 def size @encoded_size end |