question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get DST WriteStream is resolved before writeStream is done

See original GitHub issue

Hi, I’m using the latest version 7.2.0 but I’m not able to use the file right away after DST. My workaround for now is to add sleep/timeout function to wait for around 500ms before using the file, but I don’t want to do this because I don’t know how long it’ll take for bigger files. Please see my code below:

try {
        const sftp = new Client()
        await sftp.connect(sftpConfig)
        const writeStream = gcsBucket.file(path).createWriteStream() // GCS bucket writeStream
        const data = await sftp.get(sftpPath, writeStream)
        /* // Work around
        const timeout = () => new Promise(resolve => setTimeout(resolve, 500))
        await timeout() */
    } catch (error) {
      ....
    } finally {
      await sftp.end()
    }
  • ssh2-sftp-client 7.2.0
  • Node version 14.0.0
  • Windows

I also tried downgrading to 7.1.0 and 7.0.4 but none of them work. Please help. Thank you.

[Note: ] I was previously using version 6.0.1 and never had this issue.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
theophilusxcommented, Dec 16, 2021

Have updated code to resolve on finish rather than close event for the write stream. Let me know if this resolves your issue.

1reaction
theophilusxcommented, Dec 16, 2021

OK, I will push a new version to npmjs.com tomorrow.

Read more comments on GitHub >

github_iconTop Results From Across the Web

event associated with fs.createWriteStream in node.js
Main issue is - createWriteStream is not finished [due to whatever reasn] - by the time the async function that contains it -...
Read more >
How to know when writeStream is completed? #147 - GitHub
I need to know when a createWriteStream has fully completed. I tried on events for end, finish and unpipe and all of them...
Read more >
Structured Streaming Programming Guide - Apache Spark
To do that, you have to use the DataStreamWriter (Scala/Java/Python docs) returned through Dataset.writeStream() . You will have to specify one or more...
Read more >
Getting Started with Node Streams - CODE Magazine
createReadStream('test.txt'); const writeStream = fs. ... Note that the event listener is wired up before calling the Pipe method.
Read more >
Node.js fs.createWriteStream() Method - GeeksforGeeks
The createWriteStream() method is an inbuilt application programming interface of fs module which allows to quickly make a writable stream ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found