func (s *Segment) Finalize(nextSegment time.Duration) {
	s.mu.Lock()
	s.final = true
	if nextSegment > s.start {
		s.dur = nextSegment - s.start
	}
	for i := range s.parts {
		s.parts[i].Bytes = nil
	}
	s.mu.Unlock()
	s.cond.Broadcast()
}
Finalize a live segment, marking that no more parts will be added
package segment
import (
	"bytes"
	"errors"
	"fmt"
	"io/ioutil"
	"os"
	"strings"
	"sync"
	"time"
	"eaglesong.dev/hls/internal/fragment"
)
type Segment struct {
	base, suf   string
	start       time.Duration
	dcn         bool
	programTime string
	ctype       string
	mu    sync.Mutex
	cond  sync.Cond
	parts []fragment.Fragment
	f     *os.File
	final bool
	size  int64
	dur   time.Duration
}
func New(name, workDir, ctype string, start time.Duration, dcn bool, programTime time.Time) (*Segment, error) {
	i := strings.LastIndexByte(name, '.')
	if i < 0 {
		return nil, errors.New("invalid segment basename")
	}
	s := &Segment{
		base:  name[:i],
		suf:   name[i:],
		ctype: ctype,
		start: start,
		dcn:   dcn,
	}
	s.cond.L = &s.mu
	if !programTime.IsZero() {
		s.programTime = programTime.UTC().Format("2006-01-02T15:04:05.999Z07:00")
	}
	var err error
	s.f, err = ioutil.TempFile(workDir, name)
	if err != nil {
		return nil, err
	}
	os.Remove(s.f.Name())
	return s, nil
}
func (s *Segment) Append(frag fragment.Fragment) error {
	s.mu.Lock()
	s.parts = append(s.parts, frag)
	s.size += int64(frag.Length)
	s.mu.Unlock()
	s.cond.Broadcast()
	_, err := s.f.Write(frag.Bytes)
	return err
}
func (s *Segment) Discontinuous() bool { return s.dcn }
func (s *Segment) Duration() time.Duration { return s.dur }
func (s *Segment) Final() bool { return s.final }
func (s *Segment) Parts() int { return len(s.parts) }
func (s *Segment) Size() int64 { return s.size }
func (s *Segment) Start() time.Duration {
	return s.start
}