code: function pauseStream(stream) {
      function _buffer(chunk) {
          stream.__buffered.push(chunk);
      }
  
      function _catchEnd(chunk) {
          stream.__dockerreg_ended = true;
      }
  
      stream.__dockerreg_ended = false;
      stream.__dockerreg_paused = true;
      stream.__buffered = [];
      stream.on('data', _buffer);
      stream.once('end', _catchEnd);
      stream.pause();
  
      stream._resume = stream.resume;
      stream.resume = function _dockerreg_resume() {
          if (!stream.__dockerreg_paused)
              return;
  
          stream.removeListener('data', _buffer);
          stream.removeListener('end', _catchEnd);
  
          stream.__buffered.forEach(stream.emit.bind(stream, 'data'));
          stream.__buffered.length = 0;
  
          stream._resume();
          stream.resume = stream._resume;
  
          if (stream.__dockerreg_ended)
              stream.emit('end');
      };
  }
docs: Note: Borrowed from muskie.git/lib/common.js around node 0.8 days.
  I think I'm living in the past in still using this.
  
  This *could* be avoided with node 0.10, but would require the client
  knowing to avoid accidentally getting the stream (from getImgFileStream)
  into "flowing" mode -- e.g. from attaching a 'data' event listener or
  similar. Both answers suck. So until we are at node 0.12 minimum we will
  choose to use pause/resume. IOW, the caller must resume the stream.