function readAtMost(stream, amount)
{
return new Promise(async function(resolve, reject)
{
// Must be less than amount.
var data = stream.read(amount) || stream.read();
if (data !== null)
return resolve(data);
await waitForEvent("readable");
return readAtMost(stream, amount);
});
}