Fix bug when writing data with offset equal to current file size