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.

I can't perform a second get using the same write stream

See original GitHub issue

The most basic example to reproduce the issue it’s just trying to concat the content of two existing files:

const writeStream = fs.createWriteStream('./concat-result');
await sftp.get('remote/file0', writeStream);
await sftp.get('remote/file1', writeStream);

The execution hangs in the file1 call, and the contact-result file only contains the content of the file0 file. Using { autoClose: false } in the first call didn’t work. Maybe a lack of knowledge, but I really don’t know what I’m doing wrong!

Thank you very much!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
theophilusxcommented, Jun 4, 2021

I have re-factored the option handling for both get() and put() which should now work. The options argument is now an object with properties for readStreamOptions, writeStreamOptions and pipeOptions. Each property should be an object containing the options to apply to any read or write streams created by the method or the pipe() call. In your use case, you want to set the options.pipeOptions.end = false to stop the mthod from sending an ‘end’ event to the write stream. It may also be necessary to turn write stream autoClose off with options.writeStreamOptions.autoClose = false (but not 100% sure on that).

The current master branch is now based on the new ssh2 v1.1.0 module. I will be releasing a new ssh2-sftp-client version in about a week.

0reactions
theophilusxcommented, Jun 18, 2021

New version 7.0.0 of ssh2-sftp-client has been pushed to npmjs.com. This version includes changes to get()/put() option handling to support re-use of streams (as well as other things). See updated manual entry for details of new option format.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Unable to use one readable stream to write to two ...
The problem comes when I try to use the same readable data again in the same async function. Please note, all of this...
Read more >
Piping twice to same Writable stream via two different ... - GitHub
I am trying to concatenate a string and a Readable stream (the readable stream is pointing to a file which may have data...
Read more >
Stream | Node.js v19.3.0 Documentation
Writable streams are an abstraction for a destination to which data is written. Examples of Writable streams include: HTTP requests, on the client...
Read more >
Streams—The definitive guide - web.dev
The Streams API allows JavaScript to programmatically access streams of data received over the network and process them as desired.
Read more >
Use Streams to Build High-Performing Node.js Applications
on("data", (chunk) => { console.log(`Read ${chunk.length} bytes`); bytesRead += chunk.length; // Pause the readable stream after reading 60 ...
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