Sha256: 5fe7c9c636b071c1462ed2b4a725f5b107b304052ed42a687fd19123bac977ef

Contents?: true

Size: 1.15 KB

Versions: 6

Compression:

Stored size: 1.15 KB

Contents

# Copyright (C) 2006  Mauricio Fernandez <mfp@acm.org>
#

module FTSearch

class FulltextReader
  DEFAULT_OPTIONS = {
    :path => nil,
    :io   => nil,
  }
  def initialize(options = {})
    options = DEFAULT_OPTIONS.merge(options)
    unless options[:path] || options[:io]
      raise ArgumentError, "Need either the path to the suffix array file or an IO."
    end
    init_internal_structures(options)
  end

  def get_data(offset, size)
    @io.pos = offset
    @io.read(size)
  end

  def dump_data(&block)
    blocksize = 32768
    @io.pos = 0
    begin
      size = @io.stat.size - 1
    rescue NoMethodError # try with StringIO's interface
      size = @io.string.size - 1
    end
    read = 0
    #buffer = " " * blocksize
    while read < size
      #@io.read([size - read, blocksize].min, buffer)
      #yield buffer
      data = @io.read([size - read, blocksize].min)
      read += data.size
      yield data
    end
  end

  private
  def init_internal_structures(options)
    if options[:path]
      @io = File.open(options[:path], "rb")
    else
      @io = options[:io]
    end
  end
end
end #  FTSearch

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
shoesgem-0.1480.0 shoes/ruby/lib/ftsearch/fulltext_reader.rb
shoesgem-0.1469.0 shoes/ruby/lib/ftsearch/fulltext_reader.rb
shoesgem-0.1430.0 shoes/ruby/lib/ftsearch/fulltext_reader.rb
shoesgem-0.1429.0 shoes/ruby/lib/ftsearch/fulltext_reader.rb
shoesgem-0.1428.0 shoes/ruby/lib/ftsearch/fulltext_reader.rb
shoesgem-0.1426.0 shoes/ruby/lib/ftsearch/fulltext_reader.rb