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)
| 26 | // Files are split on offsets where a \n is found, but if no \n is found the |
| 27 | // file isn't split. |
| 28 | func 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 | |
| 48 | const ( |
| 49 | fflags = os.O_APPEND | os.O_CREATE | os.O_WRONLY |