func (w *Writer) checkLastByte() error {
	if w.i == 0 {
		return nil
	}
	b := w.line[w.i-1]
	if isWhitespace(b) {
		w.i--
		if err := w.encode(b); err != nil {
			return err
		}
	}
	return nil
}
checkLastByte encodes the last buffered byte if it is a space or a tab.
package quotedprintable
import "io"
const lineMaxLen = 76
type Writer struct {
	Binary bool
	w    io.Writer
	i    int
	line [78]byte
	cr   bool
}
func NewWriter(w io.Writer) *Writer {
	return &Writer{w: w}
}
func (w *Writer) Write(p []byte) (n int, err error) {
	for i, b := range p {
		switch {
		case b >= '!' && b <= '~' && b != '=':
			continue
		case isWhitespace(b) || !w.Binary && (b == '\n' || b == '\r'):
			continue
		}
		if i > n {
			if err := w.write(p[n:i]); err != nil {
				return n, err
			}
			n = i
		}
		if err := w.encode(b); err != nil {
			return n, err
		}
		n++
	}
	if n == len(p) {
		return n, nil
	}
	if err := w.write(p[n:]); err != nil {
		return n, err
	}
	return len(p), nil
}
func (w *Writer) Close() error {
	if err := w.checkLastByte(); err != nil {
		return err
	}
	return w.flush()
}
func (w *Writer) write(p []byte) error {
	for _, b := range p {
		if b == '\n' || b == '\r' {
			if w.cr && b == '\n' {
				w.cr = false
				continue
			}
			if b == '\r' {
				w.cr = true
			}
			if err := w.checkLastByte(); err != nil {
				return err
			}
			if err := w.insertCRLF(); err != nil {
				return err
			}
			continue
		}
		if w.i == lineMaxLen-1 {
			if err := w.insertSoftLineBreak(); err != nil {
				return err
			}
		}
		w.line[w.i] = b
		w.i++
		w.cr = false
	}
	return nil
}
func (w *Writer) encode(b byte) error {
	if lineMaxLen-1-w.i < 3 {
		if err := w.insertSoftLineBreak(); err != nil {
			return err
		}
	}
	w.line[w.i] = '='
	w.line[w.i+1] = upperhex[b>>4]
	w.line[w.i+2] = upperhex[b&0x0f]
	w.i += 3
	return nil
}