()
| 79 | } |
| 80 | |
| 81 | func (this *FileWriter) Close() error { |
| 82 | defer func() { |
| 83 | this.bFile.removeWritingFile(this.hash) |
| 84 | }() |
| 85 | |
| 86 | if !this.isPartial && !this.hasMeta { |
| 87 | return errors.New("no meta found") |
| 88 | } |
| 89 | |
| 90 | if this.isPartial { |
| 91 | if this.originOffset > this.bodySize { |
| 92 | return errors.New("unexpected body size") |
| 93 | } |
| 94 | this.realBodySize = this.bodySize |
| 95 | } else { |
| 96 | if this.bodySize > 0 && this.bodySize != this.realBodySize { |
| 97 | return errors.New("unexpected body size") |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | err := this.bFile.mFile.WriteClose(this.hash, this.realHeaderSize, this.realBodySize) |
| 102 | if err != nil { |
| 103 | return err |
| 104 | } |
| 105 | |
| 106 | return this.bFile.Sync() |
| 107 | } |
| 108 | |
| 109 | func (this *FileWriter) Discard() error { |
| 110 | // TODO 需要测试 |
nothing calls this directly
no test coverage detected