fixed premature finishing of httpclient.downloadFile
This commit is contained in:
parent
1961e444c3
commit
45765601e0
2 changed files with 8 additions and 12 deletions
|
|
@ -484,7 +484,5 @@ proc writeFromStream(f: AsyncFile, fut: FutureStream[string]) {.async.} =
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
proc getWriteStream*(f: AsyncFile): FutureStream[string] =
|
proc setWriteStream*(f: AsyncFile; fut: FutureStream[string]) {.async.} =
|
||||||
## Returns a new stream that can be used for writing to the file.
|
await writeFromStream(f, fut)
|
||||||
result = newFutureStream[string]()
|
|
||||||
asyncCheck writeFromStream(f, result)
|
|
||||||
|
|
|
||||||
|
|
@ -1247,15 +1247,13 @@ proc downloadFile*(client: HttpClient | AsyncHttpClient,
|
||||||
client.bodyStream = newFileStream(filename, fmWrite)
|
client.bodyStream = newFileStream(filename, fmWrite)
|
||||||
if client.bodyStream.isNil:
|
if client.bodyStream.isNil:
|
||||||
fileError("Unable to open file")
|
fileError("Unable to open file")
|
||||||
else:
|
parseBody(client, resp.headers, resp.version)
|
||||||
var f = openAsync(filename, fmWrite)
|
|
||||||
client.bodyStream = f.getWriteStream()
|
|
||||||
|
|
||||||
await parseBody(client, resp.headers, resp.version)
|
|
||||||
|
|
||||||
when client is HttpClient:
|
|
||||||
client.bodyStream.close()
|
client.bodyStream.close()
|
||||||
else:
|
else:
|
||||||
|
client.bodyStream = newFutureStream[string]()
|
||||||
|
var f = openAsync(filename, fmWrite)
|
||||||
|
asyncCheck parseBody(client, resp.headers, resp.version)
|
||||||
|
await f.setWriteStream(client.bodyStream)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
if resp.code.is4xx or resp.code.is5xx:
|
if resp.code.is4xx or resp.code.is5xx:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue