Skip to content

Instantly share code, notes, and snippets.

@inohiro
Created August 15, 2013 15:32
Show Gist options
  • Save inohiro/6241797 to your computer and use it in GitHub Desktop.
Save inohiro/6241797 to your computer and use it in GitHub Desktop.
Detect fbx format (Binary one or ASCII one) with ruby
FILE_PATH = File.expand_path './file.fbx'
CORRECT = %w"K a y d a r a \ F B X \ B i n a r y \ \ "
def binary_fbx? file_path
File.open( file_path, 'rb' ) do |file|
CORRECT.each do |char|
num = file.read( 1 )
false if num != char
end
false if file.read( 1 ) != "\x00"
false if file.read( 2 ) != "\x1A\x00" # Byte 21-22
# version = file.read( 4 ) # Byte 23-26
# int_version = version.unpack("L") # 32 bit integer
true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment