Write 写入数据
(data []byte)
| 65 | |
| 66 | // Write 写入数据 |
| 67 | func (this *MemoryWriter) Write(data []byte) (n int, err error) { |
| 68 | var l = len(data) |
| 69 | if l == 0 { |
| 70 | return |
| 71 | } |
| 72 | |
| 73 | if this.item.IsPrepared { |
| 74 | if this.item.WriteOffset+int64(l) > this.expectedBodySize { |
| 75 | err = ErrWritingUnavailable |
| 76 | return |
| 77 | } |
| 78 | copy(this.item.BodyValue[this.item.WriteOffset:], data) |
| 79 | this.item.WriteOffset += int64(l) |
| 80 | } else { |
| 81 | this.item.BodyValue = append(this.item.BodyValue, data...) |
| 82 | } |
| 83 | |
| 84 | this.bodySize += int64(l) |
| 85 | |
| 86 | // 检查尺寸 |
| 87 | if this.maxSize > 0 && this.bodySize > this.maxSize { |
| 88 | err = ErrEntityTooLarge |
| 89 | this.storage.IgnoreKey(this.key, this.maxSize) |
| 90 | return l, err |
| 91 | } |
| 92 | |
| 93 | return l, nil |
| 94 | } |
| 95 | |
| 96 | // WriteAt 在指定位置写入数据 |
| 97 | func (this *MemoryWriter) WriteAt(offset int64, b []byte) error { |