add test for file truncation, fix truncation