Functions readall/writeall to handle partial IO