renovate/lib/util/streams.ts
Kenneth Jorgensen 6ea0d5d6fb
feat(maven): S3 Support (#14938)
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
Co-authored-by: Sergei Zharinov <zharinov@users.noreply.github.com>
Co-authored-by: Rhys Arkins <rhys@arkins.net>
2022-05-04 05:59:14 +02:00

14 lines
481 B
TypeScript

import { Readable } from 'stream';
export async function streamToString(
stream: NodeJS.ReadableStream
): Promise<string> {
const readable = Readable.from(stream);
const chunks: Uint8Array[] = [];
const p = await new Promise<string>((resolve, reject) => {
readable.on('data', (chunk) => chunks.push(Buffer.from(chunk)));
readable.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
readable.on('error', (err) => reject(err));
});
return p;
}