-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdumper.rb
37 lines (31 loc) · 800 Bytes
/
dumper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module RDB
module Dumper
include ReaderCallbacks
def initialize(source, destination, options = {})
@source = source
@destination = destination
@options = options
@output = nil
end
def <<(buffer)
@output << buffer unless @output.nil?; nil
end
def with_streams(&block)
input = open(@source, 'rb') unless @source.kind_of? IO
output = open(@destination, 'wb') unless @destination.kind_of? IO
begin
block.call(input, output)
ensure
input.close
output.close
end
end
def dump
raise RuntimeException, 'Output stream already opened' if @output
with_streams do |input, output|
@output = output
Reader.read(input, callbacks: self)
end
end
end
end