Fixed bugs on manipulating small files

Fixed some subtle bugs spring up while manipulating the files smaller than the reading buffer size.