io: rewind to start during length calculation; main: dynamic sizes in read implementation