For this function in particular it's probably a better idea to call file:sendfile/2 directly and avoid the overhead.