Class: Flare::Tools::Cli::Restore::TchRestorer

Inherits:
Restorer
  • Object
show all
Defined in:
lib/flare/tools/cli/restore.rb

Instance Attribute Summary

Attributes inherited from Restorer

#name

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filepath) ⇒ TchRestorer

Returns a new instance of TchRestorer.



45
46
47
48
49
50
# File 'lib/flare/tools/cli/restore.rb', line 45

def initialize filepath
  raise "output file not specified." if filepath.nil?
  raise "#{filepath} isn't a path." unless filepath.kind_of?(String)
  @hdb = TokyoCabinet::HDB.new
  @hdb.open(filepath, TokyoCabinet::HDB::OCREAT|TokyoCabinet::HDB::OREADER)
end

Class Method Details

.mynameObject

uint32_t flag -> L // uint32_t time_t expire -> Q // unsigned long uint64_t size -> Q // uint64_t uint64_t version -> Q // uint64_t uint32_t option -> L // uint32_t



42
43
44
# File 'lib/flare/tools/cli/restore.rb', line 42

def self.myname
  "tch"
end

Instance Method Details

#closeObject



61
62
63
# File 'lib/flare/tools/cli/restore.rb', line 61

def close
  @hdb.close
end

#iterate(&block) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/flare/tools/cli/restore.rb', line 51

def iterate &block
  @hdb.iterinit
  while (key = @hdb.iternext)
    value = @hdb.get(key)
    a = value.unpack("LQQQC*")
    flag, expire, size, version = a.shift(4)
    data = a.pack("C*")
    block.call(key, data, flag, expire)
  end
end