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: 
How about still using stream and async, but also using async iterator (`for await`)?

```
async function collectStream()
    let whole = [];
    for await (const chunk of outputStream) {
        whole.push(chunk);
    }
    return whole;
}

// another async function somewhere
async function main() {
    await collectStream();
}

```

But what if you *really* need to make it async? You can use [deasync](https://www.npmjs.com/package/deasync) on `collectStream().then`. `deasync.loopWhile` can turn promise (async function) or callback into a sync one.

It's okay for a single-tenant app like CLI tools, but I don't recommend it on a multi-tenant system like a web server, as you could block the event loop. It's better to use async functions instead on web servers.
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.