Advertisement
Jessehz

periodlength.rb

Sep 11th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.49 KB | None | 0 0
  1. stream = File.open(ARGV.shift)
  2. blksize = stream.stat.blksize
  3. bytes_required = 32
  4. start = stream.read(bytes_required)
  5. match = String.new
  6. buffer = String.new
  7.  
  8. while stream.read(blksize, buffer)
  9.     buffer.bytes.with_index do |byte, index|
  10.         match.concat(byte)
  11.         start.start_with?(match) or next match.clear
  12.         match.eql?(start) and break begin
  13.             puts("Sequence restarted at:")
  14.             puts(stream.pos-blksize+index-bytes_required)
  15.             abort(match)
  16.         end
  17.     end or break
  18. end
  19.  
  20. puts("Found nothing.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement