Close 关闭
()
| 191 | |
| 192 | // Close 关闭 |
| 193 | func (this *PartialFileWriter) Close() error { |
| 194 | defer this.once.Do(func() { |
| 195 | this.endFunc() |
| 196 | }) |
| 197 | |
| 198 | this.ranges.BodySize = this.bodySize |
| 199 | err := this.ranges.WriteToFile(this.rangePath) |
| 200 | if err != nil { |
| 201 | _ = this.rawWriter.Close() |
| 202 | this.remove() |
| 203 | return err |
| 204 | } |
| 205 | |
| 206 | // 关闭当前writer |
| 207 | if this.isNew { |
| 208 | err = this.WriteHeaderLength(types.Int(this.headerSize)) |
| 209 | if err != nil { |
| 210 | _ = this.rawWriter.Close() |
| 211 | this.remove() |
| 212 | return err |
| 213 | } |
| 214 | err = this.WriteBodyLength(this.bodySize) |
| 215 | if err != nil { |
| 216 | _ = this.rawWriter.Close() |
| 217 | this.remove() |
| 218 | return err |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | err = this.rawWriter.Close() |
| 223 | if err != nil { |
| 224 | this.remove() |
| 225 | } |
| 226 | |
| 227 | return err |
| 228 | } |
| 229 | |
| 230 | // Discard 丢弃 |
| 231 | func (this *PartialFileWriter) Discard() error { |
nothing calls this directly
no test coverage detected