function bufferStream(stream, maxLength) {
  maxLength = maxLength || Infinity;

  if (!stream.readable)
    throw new Error('Cannot buffer stream that is not readable');