working but not returning correctly the number of readed bytes