Class: Worochi::Agent::Github::Helper::Base64IO

Inherits:
Object
  • Object
show all
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

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.

Returns:

  • (Boolean)

    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

Parameters:

  • length (Integer) (defaults to: size)
  • outbuf (IO) (defaults to: nil)

Returns:

  • (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

#rewindObject

Rewind the stream.



93
94
95
96
97
# File 'lib/worochi/helper/github_helper.rb', line 93

def rewind
  @file.rewind
  @buffer = ''
  nil
end

#sizeInteger

Returns size of the JSON.

Returns:

  • (Integer)

    size of the JSON



83
84
85
# File 'lib/worochi/helper/github_helper.rb', line 83

def size
  @encoded_size
end