Class: MysqlBinlog::BinlogStreamReader

Inherits:
Object
  • Object
show all
Defined in:
lib/mysql_binlog/reader/binlog_stream_reader.rb

Overview

Read a binary log from a stream dumped using the MysqlBinlogDump library to request a COM_BINLOG_DUMP from a MySQL server via the Mysql library.

Instance Method Summary collapse

Constructor Details

#initialize(connection, filename, position) ⇒ BinlogStreamReader

Returns a new instance of BinlogStreamReader.



6
7
8
9
10
11
12
13
14
# File 'lib/mysql_binlog/reader/binlog_stream_reader.rb', line 6

def initialize(connection, filename, position)
  require 'mysql_binlog_dump'
  @filename = nil
  @position = nil
  @packet_data = nil
  @packet_pos  = nil
  @connection = connection
  MysqlBinlogDump.binlog_dump(connection, filename, position)
end

Instance Method Details

#end?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/mysql_binlog/reader/binlog_stream_reader.rb', line 37

def end?
  false
end

#filenameObject



21
22
23
# File 'lib/mysql_binlog/reader/binlog_stream_reader.rb', line 21

def filename
  @filename
end

#positionObject



25
26
27
# File 'lib/mysql_binlog/reader/binlog_stream_reader.rb', line 25

def position
  @position
end

#read(length) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/mysql_binlog/reader/binlog_stream_reader.rb', line 55

def read(length)
  unless @packet_data
    read_packet
    return nil unless @packet_data
  end
  pos = @packet_pos
  @position   += length if @position
  @packet_pos += length
  @packet_data[pos...(pos+length)]
end

#read_packetObject



50
51
52
53
# File 'lib/mysql_binlog/reader/binlog_stream_reader.rb', line 50

def read_packet
  @packet_data = MysqlBinlogDump.next_packet(@connection)
  @packet_pos  = 0
end

#remaining(header) ⇒ Object



41
42
43
# File 'lib/mysql_binlog/reader/binlog_stream_reader.rb', line 41

def remaining(header)
  @packet_data.length - @packet_pos
end

#rewindObject



29
30
31
# File 'lib/mysql_binlog/reader/binlog_stream_reader.rb', line 29

def rewind
  false
end

#rotate(filename, position) ⇒ Object



16
17
18
19
# File 'lib/mysql_binlog/reader/binlog_stream_reader.rb', line 16

def rotate(filename, position)
  @filename = filename
  @position = position
end

#skip(header) ⇒ Object



45
46
47
48
# File 'lib/mysql_binlog/reader/binlog_stream_reader.rb', line 45

def skip(header)
  @packet_data = nil
  @packet_pos  = nil
end

#tellObject



33
34
35
# File 'lib/mysql_binlog/reader/binlog_stream_reader.rb', line 33

def tell
  @packet_pos
end