MCPcopy Create free account
hub / github.com/AdRoll/baker / doNextSplit

Function doNextSplit

pkg/splitwriter/split_writer.go:189–219  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

187// doNextSplit splits f at offset off, transfering the data to the next split.
188// It returns the next split.
189func 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

Callers 1

doSplitFunction · 0.85

Calls 4

openFunction · 0.85
closeFilesFunction · 0.85
CopyMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected