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

Function New

pkg/splitwriter/split_writer.go:28–46  ·  view source on GitHub ↗

New returns an io.WriteCloser that writes to fname; when it's closed, fname will be split in multiple files each of which having at most maxsize bytes. Files are split on offsets where a \n is found, but if no \n is found the file isn't split.

(fname string, maxsize, bufsize int64)

Source from the content-addressed store, hash-verified

26// Files are split on offsets where a \n is found, but if no \n is found the
27// file isn't split.
28func New(fname string, maxsize, bufsize int64) (io.WriteCloser, error) {
29 // Ensure split buffer is smaller than the split size.
30 if maxsize < bufsize {
31 return nil, fmt.Errorf("SplitWriter: maxsize < bufsize")
32 }
33
34 w := &splitWriter{
35 maxsize: maxsize,
36 bufsize: bufsize,
37 }
38
39 f, err := openSplit(fname)
40 if err != nil {
41 return nil, fmt.Errorf("SplitWriter: openSplit: %v", err)
42 }
43 w.f = f
44 w.fname = f.Name()
45 return w, nil
46}
47
48const (
49 fflags = os.O_APPEND | os.O_CREATE | os.O_WRONLY

Callers 2

TestSplitWriterFunction · 0.70
TestSplitWriterErrFunction · 0.70

Calls 1

openSplitFunction · 0.85

Tested by 2

TestSplitWriterFunction · 0.56
TestSplitWriterErrFunction · 0.56