In swift i solved this issue by sending empty string in Accept-Encoding header field of the url request. Total bytes expected to write now returns the actual size in bytes of the file being downloaded.
var request = URLRequest(url: url)
request.addValue("", forHTTPHeaderField: "Accept-Encoding")