Class: Droonga::BufferedTCPSocket::Chunk
- Inherits:
-
Object
- Object
- Droonga::BufferedTCPSocket::Chunk
- Defined in:
- lib/droonga/buffered_tcp_socket.rb
Constant Summary collapse
- SUFFIX =
".chunk"
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#time_stamp ⇒ Object
readonly
Returns the value of attribute time_stamp.
Class Method Summary collapse
Instance Method Summary collapse
- #buffering ⇒ Object
-
#initialize(data_directory, data, time_stamp, revision) ⇒ Chunk
constructor
A new instance of Chunk.
- #written ⇒ Object
- #written_partial(size) ⇒ Object
Constructor Details
#initialize(data_directory, data, time_stamp, revision) ⇒ Chunk
Returns a new instance of Chunk.
124 125 126 127 128 129 |
# File 'lib/droonga/buffered_tcp_socket.rb', line 124 def initialize(data_directory, data, time_stamp, revision) @data_directory = data_directory @data = data @time_stamp = time_stamp.utc @revision = revision end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
123 124 125 |
# File 'lib/droonga/buffered_tcp_socket.rb', line 123 def data @data end |
#time_stamp ⇒ Object (readonly)
Returns the value of attribute time_stamp.
123 124 125 |
# File 'lib/droonga/buffered_tcp_socket.rb', line 123 def time_stamp @time_stamp end |
Class Method Details
.load(path) ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/droonga/buffered_tcp_socket.rb', line 113 def load(path) data_directory = path.dirname time_stamp1, time_stamp2, revision, = path.basename.to_s.split(".", 4) data = path.open("rb") {|file| file.read} time_stamp = Time.iso8601("#{time_stamp1}.#{time_stamp2}") revision = Integer(revision) new(data_directory, data, time_stamp, revision) end |
Instance Method Details
#buffering ⇒ Object
131 132 133 134 135 |
# File 'lib/droonga/buffered_tcp_socket.rb', line 131 def buffering path.open("wb") do |file| file.write(@data) end end |
#written ⇒ Object
137 138 139 |
# File 'lib/droonga/buffered_tcp_socket.rb', line 137 def written FileUtils.rm_f(path.to_s) end |
#written_partial(size) ⇒ Object
141 142 143 144 145 146 |
# File 'lib/droonga/buffered_tcp_socket.rb', line 141 def written_partial(size) written @data = data[size..-1] @revision += 1 buffering end |