UNPKG

webmat

Version:

Formats your entire project with clang-format

44 lines 1.33 kB
"use strict"; /** * @license * Copyright (c) 2018 Google Inc. All rights reserved. * This code may only be used under the BSD style license found at * http://polymer.github.io/LICENSE.txt * Code distributed by Google as part of this project is also * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */ Object.defineProperty(exports, "__esModule", { value: true }); /** * Caches the output of a stream.Readable in a Promise string. */ class ReadableStreamCache { /** * @param stream Stream to be cached. */ constructor(stream) { this.streamCached = this.readStream(stream); } /** * Reads a stream and returns a promise that resolves with its contents when * stream ends. * * @param stream Stream to be cached */ readStream(stream) { let resolveStreamCached; const streamCached = new Promise((res) => { resolveStreamCached = res; }); let streamOutput = ''; stream.on('data', function (data) { streamOutput += data.toString(); }); stream.on('end', () => { resolveStreamCached(streamOutput); }); return streamCached; } } exports.ReadableStreamCache = ReadableStreamCache; //# sourceMappingURL=util.js.map