Fixed issue "Bad file descriptor" when using "add_chunk"

When use "add_chunk" method to an existed file, I got an error message "Bad file descriptor". This patch fixed the problem.