Skip to content

Commit

Permalink
[gatsby-source-filesystem/createRemoteFileNode] wait for file stream …
Browse files Browse the repository at this point in the history
…to finish, not just for response
  • Loading branch information
pieh committed Apr 6, 2018
1 parent f322e6d commit 5cba06c
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ async function pushToQueue(task, cb) {
const requestRemoteNode = (url, headers, tmpFilename, filename) =>
new Promise((resolve, reject) => {
const responseStream = got.stream(url, { ...headers, timeout: 30000 })
responseStream.pipe(fs.createWriteStream(tmpFilename))
const fsWriteStream = fs.createWriteStream(tmpFilename)
responseStream.pipe(fsWriteStream)
responseStream.on(`downloadProgress`, pro => console.log(pro))

// If there's a 400/500 response or other error.
Expand All @@ -143,7 +144,9 @@ const requestRemoteNode = (url, headers, tmpFilename, filename) =>
})

responseStream.on(`response`, response => {
resolve(response)
fsWriteStream.on(`finish`, () => {
resolve(response)
})
})
})

Expand Down

0 comments on commit 5cba06c

Please sign in to comment.