I think your hunch about how to handle it is right. Unpack doesn't handle Bignums; they're classically fairly tricky specifically because they don't fit in a standard 64-bit int.
You could manually "unpack" it, via something like:
str.unpack("C*").reverse.each_with_index.inject(0) do |sum, (byte, index)|
sum + byte * (256 ** index)
end
That is, reverse the list of bytes (if on a big endian system), iterate each byte, and multiply its value by 256^position
. Ruby's BigNum kicks in once the value gets big enough, and you're able to convert byte strings into very large numbers without a hitch.
You can do the same in chunks of 32-bit (or 64-bit, if the platform supports it) ints, as well:
INT32_MAX = 256 ** [1].pack("L*").size
INT64_MAX = 256 ** [1].pack("Q*").size
str.unpack("L*").reverse.each_with_index.inject(0) do |sum, (byte, index)|
sum + byte * (INT32_MAX ** index)
end
str.unpack("Q*").reverse.each_with_index.inject(0) do |sum, (byte, index)|
sum + byte * (INT64_MAX ** index)
end