MCPcopy Index your code
hub / github.com/ampproject/amphtml / readFromReadable

Function readFromReadable

validator/js/nodejs/index.js:58–72  ·  view source on GitHub ↗

* Creates a promise which reads from a stream. * @param {string} name * @param {!stream.Readable} readable * @return {Promise }

(name, readable)

Source from the content-addressed store, hash-verified

56 * @return {Promise<string>}
57 */
58function 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

Callers 1

readFromStdinFunction · 0.85

Calls 3

resolveFunction · 0.50
onMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected