Sha256: b843ea7a6f31b6d72ed8b1247f388f0a30ba7b05fb5d96e2de179a763a5436d4

Contents?: true

Size: 1.08 KB

Versions: 101

Compression:

Stored size: 1.08 KB

Contents

#!/usr/bin/env ruby

require "knj/autoload"
include Knj

begin
  options = {}
  OptionParser.new do |opts|
    opts.banner = "Usage: example.rb [options]"
    
    opts.on("-f FINDTHIS", "--find", "Search for this string.") do |f|
      options[:find] = f
    end
    
    opts.on("-b BYTES", "--bytes BYTES", "Return this number of bytes and finding the string.") do |b|
      options[:bytes] = b.to_i
    end
    
    opts.on("--filepath FILEPATH", "The file that should be searched.") do |fp|
      options[:filepath] = fp
    end
  end.parse!
rescue OptionParser::InvalidOption => e
  Php.die(e.message + "\n")
end

cont = ""
readstr = ""
retcont = ""
File.open(options[:filepath], "r") do |fp|
  loop do
    break if fp.eof
    
    prevcont = String.new(readstr)
    readstr = fp.read(1024)
    cont = prevcont + readstr
    
    if ind = cont.index(options[:find])
      read_size = options[:bytes] - (cont.length - ind)
      
      if read_size > 0
        cont += fp.read(read_size)
      end
      
      retcont = cont.slice(ind, options[:bytes])
      break
    end
  end
end

print retcont + "\n"

Version data entries

101 entries across 101 versions & 1 rubygems

Version Path
knjrbfw-0.0.94 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.93 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.92 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.91 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.90 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.89 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.88 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.87 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.86 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.85 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.84 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.83 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.82 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.81 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.80 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.79 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.78 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.77 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.75 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.74 lib/knj/scripts/filesearch.rb