Skip to content

Instantly share code, notes, and snippets.

@michaelcinquin
Created May 9, 2016 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelcinquin/d8272675ea3c582f3c4362d0555de0e0 to your computer and use it in GitHub Desktop.
Save michaelcinquin/d8272675ea3c582f3c4362d0555de0e0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# coding: utf-8
class Scan_binary
def readBigBinaryFile(file)
# source =NSFileHandle.fileHandleForReadingAtPath(file)
source=File.open(file,'r')
buffer_size=4096
offset=0
size=File.size(file)
while ( offset + buffer_size ) <= size
# source.seekToFileOffset(offset)
# abuffer = source.readDataOfLength(buffer_size)
source.seek(offset) #PURE-RUBY
abuffer = source.read( buffer_size )
abuffer=abuffer.to_s
offset+=buffer_size
# @dataPointer ||= Pointer.new(:uchar,4)
# abuffer.getBytes(@dataPointer, length: 4)
# memory leaks very rapidly in GBs if we don't release the buffer…
# but this relase action will make the application crash once the doSomething lookp is finished
# abuffer.release
end
source.close
return false
end
end
x=0
my_scan_binary_instance=Scan_binary.new()
while x < 10000
result=my_scan_binary_instance.readBigBinaryFile("/path/to/some/big/file")
puts result.to_s
x+=1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment