doNextSplit splits f at offset off, transfering the data to the next split. It returns the next split.
(f *os.File, dir, next string, off int64)
| 187 | // doNextSplit splits f at offset off, transfering the data to the next split. |
| 188 | // It returns the next split. |
| 189 | func doNextSplit(f *os.File, dir, next string, off int64) (*os.File, error) { |
| 190 | // Transfer the excess data to the next split |
| 191 | nextpath := filepath.Join(dir, next) |
| 192 | nextf, err := open(nextpath) |
| 193 | if err != nil { |
| 194 | closeFiles(f) |
| 195 | return nil, err |
| 196 | } |
| 197 | |
| 198 | if _, err := f.Seek(off, io.SeekStart); err != nil { |
| 199 | closeFiles(f, nextf) |
| 200 | return nil, err |
| 201 | } |
| 202 | |
| 203 | if _, err := io.Copy(nextf, f); err != nil { |
| 204 | closeFiles(f, nextf) |
| 205 | return nil, err |
| 206 | } |
| 207 | |
| 208 | // Conclude the current split |
| 209 | if err := f.Truncate(off); err != nil { |
| 210 | closeFiles(f, nextf) |
| 211 | return nil, err |
| 212 | } |
| 213 | |
| 214 | if err := f.Close(); err != nil { |
| 215 | closeFiles(nextf) |
| 216 | return nil, err |
| 217 | } |
| 218 | return nextf, nil |
| 219 | } |
| 220 | |
| 221 | // doFirstSplit creates the first splits of f, at offset off. |
| 222 | // That is, from 'file' it creates both 'file.part-1' and 'file.part-2' and |
no test coverage detected