code: func (w *bufferedWriter) tryShrinkBuffer(file *os.File) (io.Writer, error) {
  	// Nothing to do if we are already at the lowest
  	// or file not set/opened.
  	if w.bufSize == w.minShrinkSize || file == nil {
  		return w.buf, nil
  	}
  
  	if !w.shrinkReq {
  		percentFilled := w.buf.Buffered() * 100 / w.bufSize
  		if percentFilled <= bufShrinkThreshold {
  			w.shrinkReq = true
  		}
  		// Wait for next tick to see if we can shrink
  		return w.buf, nil
  	}
  	if err := w.buf.Flush(); err != nil {
  		return w.buf, err
  	}
  	// Reduce size, but ensure it does not go below the limit
  	w.bufSize /= 2
  	if w.bufSize < w.minShrinkSize {
  		w.bufSize = w.minShrinkSize
  	}
  	w.buf = bufio.NewWriterSize(file, w.bufSize)
  	// Don't reset shrinkReq unless we are down to the limit
  	if w.bufSize == w.minShrinkSize {
  		w.shrinkReq = true
  	}
  	return w.buf, nil
  }
docs: // tryShrinkBuffer checks and possibly shrinks the buffer