class CFPropertyList::Binary

def read_binary_int(fname,fd,length)

read a binary int value
def read_binary_int(fname,fd,length)
  if length > 3
    raise CFFormatError.new("Integer greater than 8 bytes: #{length}")
  end
  nbytes = 1 << length
  buff = fd.read(nbytes)
  CFInteger.new(
    case length
    when 0 then buff.unpack("C")[0]
    when 1 then buff.unpack("n")[0]
    when 2 then buff.unpack("N")[0]
    when 3
      hiword,loword = buff.unpack("NN")
      if (hiword & 0x80000000) != 0
        # 8 byte integers are always signed, and are negative when bit 63 is
        # set. Decoding into either a Fixnum or Bignum is tricky, however,
        # because the size of a Fixnum varies among systems, and Ruby
        # doesn't consider the number to be negative, and won't sign extend.
        -(2**63 - ((hiword & 0x7fffffff) << 32 | loword))
      else
        hiword << 32 | loword
      end
    end
  )
end