Question: is there a way to convert stream to buffer in sync mode?
I need to get it like:

```
let newBuffer = outputStream.getDataSync();

```

rather than `outputStream.on('data'...` like below

```
let newBuffer = convertStream(outputStream);

function convertStream(strm) {
  return new Promise((resolve, reject) => {
    const chunks = [];
    strm.on('data', (chunk) => {
      chunks.push(chunk);
    }).on('end', () => {
      resolve(Buffer.concat(chunks));
    }).on('error', (err) => {
      reject(err);
    });
  });
}

```

I cannot use await for convertStream because the function I call it from is not async

Answer: 
A Stream is a flow of data. You cannot get a buffer synchronously, as the data in the stream might already started flowing, or will arrive somewhen.

> 
> I cannot use await for convertStream because the function I call it from is not async
> 
> 
> 

Then make that function you call from async?
It is said that asynchrony is contagious: as soon as you have one asynchronous bit in your flow, all the dependent flow needs to be asynchronous. Streams are asynchronous by nature, so you can only simplify your code via synchronous-looking async-await.

BTW, the [asynchronous iterator interface for streams](https://nodejs.org/api/stream.html#stream_readable_symbol_asynciterator) may be the most concise way to do this.