* Creates a promise which reads from a stream. * @param {string} name * @param {!stream.Readable} readable * @return {Promise }
(name, readable)
| 56 | * @return {Promise<string>} |
| 57 | */ |
| 58 | function readFromReadable(name, readable) { |
| 59 | return new Promise(function(resolve, reject) { |
| 60 | const chunks = []; |
| 61 | readable.setEncoding('utf8'); |
| 62 | readable.on('data', function(chunk) { |
| 63 | chunks.push(chunk); |
| 64 | }); |
| 65 | readable.on('end', function() { |
| 66 | resolve(chunks.join('')); |
| 67 | }); |
| 68 | readable.on('error', function(error) { |
| 69 | reject(new Error('Could not read from ' + name + ' - ' + error.message)); |
| 70 | }); |
| 71 | }); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Creates a promise which reads from standard input. Even though it would |
no test coverage detected