Write encodes p in an internal buffer.
(p []byte)
| 36 | |
| 37 | // Write encodes p in an internal buffer. |
| 38 | func (e *Encoder) Write(p []byte) { |
| 39 | // Leading fringe. |
| 40 | if e.nbuf > 0 { |
| 41 | var i int |
| 42 | for i = 0; i < len(p) && e.nbuf < 3; i++ { |
| 43 | e.buf[e.nbuf] = p[i] |
| 44 | e.nbuf++ |
| 45 | } |
| 46 | p = p[i:] |
| 47 | if e.nbuf < 3 { |
| 48 | return |
| 49 | } |
| 50 | e.enc.Encode(e.out[:], e.buf[:]) |
| 51 | _, _ = e.sb.Write(e.out[:4]) |
| 52 | e.nbuf = 0 |
| 53 | } |
| 54 | |
| 55 | // Large interior chunks. |
| 56 | for len(p) >= 3 { |
| 57 | nn := len(e.out) / 4 * 3 |
| 58 | if nn > len(p) { |
| 59 | nn = len(p) |
| 60 | nn -= nn % 3 |
| 61 | } |
| 62 | e.enc.Encode(e.out[:], p[:nn]) |
| 63 | _, _ = e.sb.Write(e.out[0 : nn/3*4]) |
| 64 | p = p[nn:] |
| 65 | } |
| 66 | |
| 67 | // Trailing fringe. |
| 68 | copy(e.buf[:], p) |
| 69 | e.nbuf = int8(len(p)) |
| 70 | } |
| 71 | |
| 72 | // String flushes any pending output from the encoder and returns the encoded |
| 73 | // string. The Encoder is reset to its initial state so it can be reused. |
no test coverage detected