| 111 | } |
| 112 | |
| 113 | func (w *objectWriter) Write(data []byte) (n int, err error) { |
| 114 | w.mu.Lock() |
| 115 | defer w.mu.Unlock() |
| 116 | |
| 117 | dataLen := len(data) |
| 118 | w.totalLength += int64(dataLen) |
| 119 | |
| 120 | for len(data) > 0 { |
| 121 | n := w.splitter.NextSplitPoint(data) |
| 122 | if n < 0 { |
| 123 | // no split points in the buffer |
| 124 | w.buffer.Append(data) |
| 125 | break |
| 126 | } |
| 127 | |
| 128 | // found a split point after `n` bytes, write first n bytes then flush and repeat with the remainder. |
| 129 | w.buffer.Append(data[0:n]) |
| 130 | |
| 131 | if err := w.flushBufferLocked(); err != nil { |
| 132 | return 0, err |
| 133 | } |
| 134 | |
| 135 | data = data[n:] |
| 136 | } |
| 137 | |
| 138 | return dataLen, nil |
| 139 | } |
| 140 | |
| 141 | // +checklocks:w.mu |
| 142 | func (w *objectWriter) flushBufferLocked() error { |