(buf []byte, callback ReaderFunc)
| 81 | } |
| 82 | |
| 83 | func (this *MemoryReader) ReadBody(buf []byte, callback ReaderFunc) error { |
| 84 | l := len(buf) |
| 85 | if l == 0 { |
| 86 | return errors.New("using empty buffer") |
| 87 | } |
| 88 | |
| 89 | size := len(this.item.BodyValue) |
| 90 | offset := 0 |
| 91 | for { |
| 92 | left := size - offset |
| 93 | if l <= left { |
| 94 | copy(buf, this.item.BodyValue[offset:offset+l]) |
| 95 | goNext, e := callback(l) |
| 96 | if e != nil { |
| 97 | return e |
| 98 | } |
| 99 | if !goNext { |
| 100 | break |
| 101 | } |
| 102 | } else { |
| 103 | copy(buf, this.item.BodyValue[offset:]) |
| 104 | _, e := callback(left) |
| 105 | if e != nil { |
| 106 | return e |
| 107 | } |
| 108 | break |
| 109 | } |
| 110 | offset += l |
| 111 | if offset >= size { |
| 112 | break |
| 113 | } |
| 114 | } |
| 115 | return nil |
| 116 | } |
| 117 | |
| 118 | func (this *MemoryReader) Read(buf []byte) (n int, err error) { |
| 119 | bufLen := len(buf) |
no outgoing calls