(p []byte)
| 43 | } |
| 44 | |
| 45 | func (a *autoDecodeReadCloser) peekRead(p []byte) (n int, err error) { |
| 46 | n, err = a.ReadCloser.Read(p) |
| 47 | if n == 0 || (err != nil && err != io.EOF) { |
| 48 | return |
| 49 | } |
| 50 | a.detected = true |
| 51 | enc, name := charsets.FindEncoding(p) |
| 52 | if enc == nil { |
| 53 | return |
| 54 | } |
| 55 | if a.t.Debugf != nil { |
| 56 | a.t.Debugf("charset %s found in body's meta, auto-decode to utf-8", name) |
| 57 | } |
| 58 | dc := enc.NewDecoder() |
| 59 | a.decodeReader = dc.Reader(a.ReadCloser) |
| 60 | var pp []byte |
| 61 | pp, err = dc.Bytes(p[:n]) |
| 62 | if err != nil { |
| 63 | return |
| 64 | } |
| 65 | if len(pp) > len(p) { |
| 66 | a.peek = make([]byte, len(pp)-len(p)) |
| 67 | copy(a.peek, pp[len(p):]) |
| 68 | copy(p, pp[:len(p)]) |
| 69 | n = len(p) |
| 70 | return |
| 71 | } |
| 72 | copy(p, pp) |
| 73 | n = len(p) |
| 74 | return |
| 75 | } |
| 76 | |
| 77 | func (a *autoDecodeReadCloser) peekDrain(p []byte) (n int, err error) { |
| 78 | if len(a.peek) > len(p) { |
no test coverage detected