-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsegmentfile.go
52 lines (43 loc) · 984 Bytes
/
segmentfile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package writer
import (
"io"
"os"
"path"
"strconv"
)
const (
segmentFileExtension = ".segment"
)
type SegmentFile struct {
Name string
StartTimeStamp int64
LogDirectory string
OccupiedSize int
Size int
Path string
Out io.ReadWriteCloser
}
func NewSegmentFile(logDirectory string, startTimeStamp int64, size int) (*SegmentFile, error) {
segmentFileName := strconv.FormatInt(startTimeStamp, 10) + segmentFileExtension
segmentFilePath := path.Join(logDirectory, segmentFileName)
file, err := os.Create(segmentFilePath)
if err != nil {
return nil, err
}
return &SegmentFile{
Name: segmentFileName,
LogDirectory: logDirectory,
Size: size,
StartTimeStamp: startTimeStamp,
Out: file,
}, nil
}
func (s *SegmentFile) Writer() io.Writer {
return s.Out
}
func (s *SegmentFile) Reader() io.Reader {
return s.Out
}
func (s *SegmentFile) Close() error {
return s.Out.Close()
}