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.116 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.115 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.114 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.113 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.111 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.110 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.109 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.108 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.107 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.105 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.104 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.103 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.102 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.101 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.100 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.99 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.98 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.97 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.96 lib/knj/scripts/filesearch.rb
knjrbfw-0.0.95 lib/knj/scripts/filesearch.rb