Project

ruby-mtbl

0.0
No commit activity in last 3 years
No release in over 3 years
The ruby-mtbl gem provides a Ruby interface to Farsight Security's MTBL SortedString library.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

Ruby bindings for the mtbl sorted string table library

ruby-mtbl is a Ruby interface to Farsight Security's mtbl library, which is a C implementation of the Sorted String Table (SSTable) data structure. The latest version of mtbl depends on zlib, LZ4 (dev branch > 129), and Snappy compression libraries.

On Ubuntu 16.04 LTS, the following command will install the required dependencies:

$ sudo apt install libmtbl-dev

Usage

Generate a mtbl from unsorted input

require 'mtbl'
msorter = MTBL::Sorter.new
mwriter = MTBL::Writer.new("tiny.mtbl", MTBL::COMPRESSION_SNAPPY)
msorter.add('key1', 'val1')
msorter.add('key0', 'val2')
msorter.add('key3', 'val3')
msorter.write(mwriter)

Display metadata from a mtbl

require 'mtbl'
MTBL::Utils.metadata("tiny.mtbl").each_pair do |k,v|
  puts "#{k.to_s.gsub("_", " ")}: ".ljust(23) + v.to_s
end

Read all pairs from a mtbl

require 'mtbl'
mreader = MTBL::Reader.new("tiny.mtbl")
mreader.iterator.each do |r|
  puts r.join(" => ")
end

Read pairs starting with 'k'

require 'mtbl'
mreader = MTBL::Reader.new("tiny.mtbl")
iterator = mreader.get_prefix("k")
iterator.each do |r|
  puts r.join(" => ")
end

See the command-line tools in bin and examples/test.rb for additional usage.