Created
May 9, 2016 15:16
-
-
Save michaelcinquin/d8272675ea3c582f3c4362d0555de0e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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