struct Gdbmish::Read::Ascii
- Gdbmish::Read::Ascii
- Struct
- Value
- Object
Overview
Main abstraction to read an GDBM Ascii dump file (aka "standard format")
Example:
io = File.open("path/to/file.dump")
file = Gdbmish::Read::Ascii.new(io)
file.data do |key, value|
puts "#{key.inspect} => #{value.inspect}"
end
pp file.meta
# Note: your `io`'s file pointer posistion has changed.
io.pos # => 317
Produces:
"some_key" => "Some Value"
"otherKey" => "Other\nValue"
Gdbmish::Read::AsciiMetaData(
@count=nil,
@file="test.db",
@gid="1000",
@group="staff",
@mode=384,
@uid="1000",
@user="ziggy",
@version="1.1")
Defined in:
gdbmish/read.crConstructors
-
.new(io : IO, load_meta : Bool | Symbol = true)
Create a new Ascii reader.
Instance Method Summary
-
#data : AsciiDataIterator
Returns an Iterator over key/value pairs.
-
#data(&block : String, String | Nil -> _) : Nil
Shortcut for
data.each { |key, value| }
-
#meta : AsciiMetaData | Nil
Parses for meta data, depending on the load_meta value in
.new
Constructor Detail
def self.new(io : IO, load_meta : Bool | Symbol = true)
#
Create a new Ascii reader.
- io is assumed to point to the beginning of the GDBM dump.
- load_meta can take three values:
true
: (default) load meta data, but skipcount
for preformance reasons.false
: skip loading meta data.:count
: load meta data, includingcount
.
Instance Method Detail
def data : AsciiDataIterator
#
Returns an Iterator over key/value pairs.
Depending on the size of the dataset, you might want to read everything into an Array or Hash:
Ascii.new(io).data.to_a # => [{"some_key", "Some Value"}, {"otherKey", "Other\nValue"}]
Ascii.new(io).data.to_h # => {"some_key" => "Some Value", "otherKey" => "Other\nValue"}