fixed premature finishing of httpclient.downloadFile
This commit is contained in:
parent
1961e444c3
commit
45765601e0
2 changed files with 8 additions and 12 deletions
|
|
@ -1247,16 +1247,14 @@ proc downloadFile*(client: HttpClient | AsyncHttpClient,
|
|||
client.bodyStream = newFileStream(filename, fmWrite)
|
||||
if client.bodyStream.isNil:
|
||||
fileError("Unable to open file")
|
||||
else:
|
||||
var f = openAsync(filename, fmWrite)
|
||||
client.bodyStream = f.getWriteStream()
|
||||
|
||||
await parseBody(client, resp.headers, resp.version)
|
||||
|
||||
when client is HttpClient:
|
||||
parseBody(client, resp.headers, resp.version)
|
||||
client.bodyStream.close()
|
||||
else:
|
||||
client.bodyStream = newFutureStream[string]()
|
||||
var f = openAsync(filename, fmWrite)
|
||||
asyncCheck parseBody(client, resp.headers, resp.version)
|
||||
await f.setWriteStream(client.bodyStream)
|
||||
f.close()
|
||||
|
||||
if resp.code.is4xx or resp.code.is5xx:
|
||||
raise newException(HttpRequestError, resp.status)
|
||||
raise newException(HttpRequestError, resp.status)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue