Skip to content

Instantly share code, notes, and snippets.

@jamie
Created August 6, 2015 17:57
Show Gist options
  • Save jamie/4d9fabb419e549aa87ac to your computer and use it in GitHub Desktop.
Save jamie/4d9fabb419e549aa87ac to your computer and use it in GitHub Desktop.
data = [] of UInt32
File.open(filename, "rb") do |file|
- (file.size/4).times do
- a = (file.read_byte || 0).to_u32
- b = (file.read_byte || 0).to_u32
- c = (file.read_byte || 0).to_u32
- d = (file.read_byte || 0).to_u32
+ slice = Slice(UInt8).new(file.size.to_i)
+ file.read(slice)
+ (file.size/4).times do |w|
+ a, b, c, d = slice[(w.to_i32 * 4), 4].map{|v| v.to_u32}
data << ((a << 24) + (b << 16) + (c << 8) + d)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment