Class: Fluffy::S3Io
- Inherits:
-
IO
- Object
- IO
- Fluffy::S3Io
- Defined in:
- lib/fluffy/s3_io.rb
Instance Attribute Summary collapse
-
#bucket ⇒ Object
Returns the value of attribute bucket.
-
#data ⇒ Object
Returns the value of attribute data.
-
#key ⇒ Object
Returns the value of attribute key.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#pos ⇒ Object
Returns the value of attribute pos.
-
#read_mode ⇒ Object
readonly
Returns the value of attribute read_mode.
-
#s3 ⇒ Object
Returns the value of attribute s3.
-
#s3_path ⇒ Object
Returns the value of attribute s3_path.
-
#write_mode ⇒ Object
readonly
Returns the value of attribute write_mode.
Instance Method Summary collapse
- #close ⇒ Object
- #each(&block) ⇒ Object
- #each_line(&block) ⇒ Object
- #eof ⇒ Object
- #eof? ⇒ Boolean
- #flush ⇒ Object
- #gets(sep_string = "\n") ⇒ Object
-
#initialize(s3_path, key, mode) ⇒ S3Io
constructor
A new instance of S3Io.
- #puts(*strings) ⇒ Object
- #read(length = nil) ⇒ Object
- #readline ⇒ Object
- #readlines ⇒ Object
- #write(string = nil) ⇒ Object (also: #print, #<<)
Constructor Details
#initialize(s3_path, key, mode) ⇒ S3Io
Returns a new instance of S3Io.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fluffy/s3_io.rb', line 6 def initialize(s3_path, key, mode) self.s3_path = s3_path self.key = self.s3_path.bucket.key(key) self.data = self.key.data || '' self.mode = mode case self.mode.gsub(/b/, '') # We ignore the binary flag at this time when 'r', 'r+' self.pos = 0 @read_mode = true @write_mode = !!(self.mode =~ /\+/) when 'w', 'w+' self.data = '' self.pos = 0 @read_mode = !!(self.mode =~ /\+/) @write_mode = true when 'a', 'a+' self.pos = self.data.length @read_mode = !!(self.mode =~ /\+/) @write_mode = true end end |
Instance Attribute Details
#bucket ⇒ Object
Returns the value of attribute bucket.
3 4 5 |
# File 'lib/fluffy/s3_io.rb', line 3 def bucket @bucket end |
#data ⇒ Object
Returns the value of attribute data.
3 4 5 |
# File 'lib/fluffy/s3_io.rb', line 3 def data @data end |
#key ⇒ Object
Returns the value of attribute key.
3 4 5 |
# File 'lib/fluffy/s3_io.rb', line 3 def key @key end |
#mode ⇒ Object
Returns the value of attribute mode.
3 4 5 |
# File 'lib/fluffy/s3_io.rb', line 3 def mode @mode end |
#pos ⇒ Object
Returns the value of attribute pos.
3 4 5 |
# File 'lib/fluffy/s3_io.rb', line 3 def pos @pos end |
#read_mode ⇒ Object (readonly)
Returns the value of attribute read_mode.
4 5 6 |
# File 'lib/fluffy/s3_io.rb', line 4 def read_mode @read_mode end |
#s3 ⇒ Object
Returns the value of attribute s3.
3 4 5 |
# File 'lib/fluffy/s3_io.rb', line 3 def s3 @s3 end |
#s3_path ⇒ Object
Returns the value of attribute s3_path.
3 4 5 |
# File 'lib/fluffy/s3_io.rb', line 3 def s3_path @s3_path end |
#write_mode ⇒ Object (readonly)
Returns the value of attribute write_mode.
4 5 6 |
# File 'lib/fluffy/s3_io.rb', line 4 def write_mode @write_mode end |
Instance Method Details
#close ⇒ Object
95 96 97 |
# File 'lib/fluffy/s3_io.rb', line 95 def close flush end |
#each(&block) ⇒ Object
37 38 39 40 41 |
# File 'lib/fluffy/s3_io.rb', line 37 def each(&block) until self.eof? yield(self.gets) end end |
#each_line(&block) ⇒ Object
43 44 45 |
# File 'lib/fluffy/s3_io.rb', line 43 def each_line(&block) self.each(block) end |
#eof ⇒ Object
29 30 31 |
# File 'lib/fluffy/s3_io.rb', line 29 def eof eof? end |
#eof? ⇒ Boolean
33 34 35 |
# File 'lib/fluffy/s3_io.rb', line 33 def eof? self.pos >= self.data.length end |
#flush ⇒ Object
99 100 101 102 |
# File 'lib/fluffy/s3_io.rb', line 99 def flush self.key.put(self.data) self end |
#gets(sep_string = "\n") ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/fluffy/s3_io.rb', line 87 def gets(sep_string = "\n") sep_string = "\n\n" if sep_string == '' end_pos = self.data.index(sep_string, self.pos) || self.data.length $_ = self.read(end_pos - self.pos + 1) end |
#puts(*strings) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/fluffy/s3_io.rb', line 70 def puts(*strings) strings.each do |string| string << "\n" unless string =~ /\n$/ self.print(string) end self.flush return nil end |
#read(length = nil) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/fluffy/s3_io.rb', line 47 def read(length = nil) if length return nil if self.eof? data = self.data[self.pos, length] self.pos += length else data = self.data[self.pos .. -1] self.pos = self.data.length end return data end |
#readline ⇒ Object
79 80 81 |
# File 'lib/fluffy/s3_io.rb', line 79 def readline self.gets end |
#readlines ⇒ Object
83 84 85 |
# File 'lib/fluffy/s3_io.rb', line 83 def readlines return self.data.split("\n") end |
#write(string = nil) ⇒ Object Also known as: print, <<
60 61 62 63 64 65 66 |
# File 'lib/fluffy/s3_io.rb', line 60 def write(string = nil) string ||= $_ string << $\ if $\ self.data[self.pos, string.length] = string self.pos += string.length return nil end |