I can't perform a second get using the same write stream
See original GitHub issueThe 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:
- Created 2 years ago
- Comments:9 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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.