read: fix for 32bit platforms, introduce int64 type for ints
write: use math.* consts instead of magic numbers and type conversion