Changed writePiece() method

Can write less bytes than piece size if last piece is less than the full
size