Node A method returns a ReadStream type, how to save the read content to a file in the specified path

https://github.com/jyu213/ssh.
this get method that operates the FTP module can read the server file and return the ReadStream type. I need to download it to the local specified path. How to do the request?

Mar.17,2021

const fs = require('fs');
const readable = getReadableStreamSomehow();
const writable = fs.createWriteStream('file.txt');
// All the data from readable goes into 'file.txt'
readable.pipe(writable);

https://nodejs.org/api/stream.


sftp.getFile(fileName).then(data => {
// data ReadStream  data.pipe(require('fs').createWriteStream(`files/download/${fileName}.csv`));
  console.log(data)
}).catch(err => {
  console.log(err);
});

Note:

   const downLoadFile =  (blob, fileName)=> {
      if (window.navigator.msSaveOrOpenBlob) { // IE10
          navigator.msSaveBlob(blob, fileName);
      } else {
          let link = document.createElement('a');
          link.style.display = 'none';
  
          link.href = URL.createObjectURL(blob); //URL
          link.download = fileName;
          link.click(); // 
          URL.revokeObjectURL(link.href); //  URL.createObjectURL()  URL
      }
  }
    const downloadQrCode = () => {
      /*
      comments by wellen
      readableStream,~ 
      
      :
      1.:responseType: 'arryBuffer';
      2.arryBuffer:.then(response => response.arrayBuffer())
      3.blob
      */
      fetch(`${config.baseUrl}/api/v1/weChat/getwxacodeunlimit`, {
        method: 'POST',
        responseType: 'arryBuffer',
        headers: {
          'Content-Type': 'application/json;charset=UTF-8',
        },
        body: JSON.stringify({
          scene: id,
          is_hyaline: true,
          width: 500,
          page: 'pages/index/index',
        }),
      }).then(response => response.arrayBuffer())
        .then(body => {
          const blob = new Blob([body], { type: 'image/png' }); // excel
          const fileName = `${id}-${new Date().getTime()}.png`; // 
          downLoadFile(blob, fileName);
        });
    };
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3a02a-2af21.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3a02a-2af21.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?