Close 关闭
()
| 129 | |
| 130 | // Close 关闭 |
| 131 | func (this *FileWriter) Close() error { |
| 132 | defer this.once.Do(func() { |
| 133 | this.endFunc() |
| 134 | }) |
| 135 | |
| 136 | var path = this.rawWriter.Name() |
| 137 | |
| 138 | // check content length |
| 139 | if this.metaBodySize > 0 && this.bodySize != this.metaBodySize { |
| 140 | _ = this.rawWriter.Close() |
| 141 | _ = fsutils.Remove(path) |
| 142 | return ErrUnexpectedContentLength |
| 143 | } |
| 144 | |
| 145 | err := this.WriteHeaderLength(types.Int(this.headerSize)) |
| 146 | if err != nil { |
| 147 | _ = this.rawWriter.Close() |
| 148 | _ = fsutils.Remove(path) |
| 149 | return err |
| 150 | } |
| 151 | err = this.WriteBodyLength(this.bodySize) |
| 152 | if err != nil { |
| 153 | _ = this.rawWriter.Close() |
| 154 | _ = fsutils.Remove(path) |
| 155 | return err |
| 156 | } |
| 157 | |
| 158 | err = this.rawWriter.Close() |
| 159 | if err != nil { |
| 160 | _ = fsutils.Remove(path) |
| 161 | } else if strings.HasSuffix(path, FileTmpSuffix) { |
| 162 | err = fsutils.Rename(path, strings.Replace(path, FileTmpSuffix, "", 1)) |
| 163 | if err != nil { |
| 164 | _ = fsutils.Remove(path) |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | return err |
| 169 | } |
| 170 | |
| 171 | // Discard 丢弃 |
| 172 | func (this *FileWriter) Discard() error { |
nothing calls this directly
no test coverage detected