aboutsummaryrefslogtreecommitdiff
path: root/format/pack/ingest/file_section_writer.go
blob: fa28c1a9291d9269daa8971328f15f93db81602f (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package ingest

import "os"

// fileSectionWriter writes sequentially to file via WriteAt at one base offset.
type fileSectionWriter struct {
	file *os.File
	off  int64
	pos  int64
}

// Write writes src at current section position.
func (writer *fileSectionWriter) Write(src []byte) (int, error) {
	if len(src) == 0 {
		return 0, nil
	}

	n, err := writer.file.WriteAt(src, writer.off+writer.pos)
	writer.pos += int64(n)

	return n, err
}