return
}
-func (m *Manifest) NormalizeManifest() map[string]ManifestStream {
- streams := make(map[string]ManifestStream)
-
- for stream := range m.StreamIter() {
- ms := streams[stream.StreamName]
-
- if ms.StreamName == "" { // new stream
- streams[stream.StreamName] = stream
- } else {
- ms.Blocks = append(ms.Blocks, stream.Blocks...)
- ms.FileStreamSegments = append(ms.FileStreamSegments, stream.FileStreamSegments...)
- }
- }
-
- return streams
-}
-
-func (m *Manifest) NormalizedManifestForPath(path string) string {
- normalized := m.NormalizeManifest()
-
- var streams []string
- for _, stream := range normalized {
- streams = append(streams, stream.StreamName)
- }
- sort.Strings(streams)
-
- path = strings.Trim(path, "/")
- var subdir, filename string
-
- if path != "" {
- if strings.Index(path, "/") == -1 {
- isStream := false
- for _, v := range streams {
- if v == "./"+path {
- isStream = true
- }
- }
- if isStream {
- subdir = path
- } else {
- filename = path
- }
- } else {
- pathIdx := strings.LastIndex(path, "/")
- if pathIdx >= 0 {
- subdir = path[0:pathIdx]
- filename = path[pathIdx+1:]
- }
- }
- }
-
- manifestForPath := ""
-
- for _, streamName := range streams {
- stream := normalized[streamName]
-
- if subdir != "" && stream.StreamName != "./"+subdir {
- continue
- }
-
- manifestForPath += stream.StreamName + " " + strings.Join(stream.Blocks, " ") + " "
-
- currentName := ""
- currentSpan := []uint64{0, 0}
- for _, fss := range stream.FileStreamSegments {
- if filename != "" && fss.Name != filename {
- continue
- }
-
- if fss.Name != currentName && currentName != "" {
- manifestForPath += fmt.Sprintf("%v", currentSpan[0]) + ":" + fmt.Sprintf("%v", currentSpan[1]) + ":" + currentName + " "
- }
-
- if fss.Name != currentName {
- currentName = fss.Name
- currentSpan = []uint64{0, 0}
- }
-
- if currentSpan[1] == 0 {
- currentSpan = []uint64{fss.SegPos, fss.SegLen}
- } else {
- if currentSpan[1] == fss.SegPos {
- currentSpan[1] += fss.SegLen
- } else if currentSpan[0]+currentSpan[1] == fss.SegPos {
- currentSpan[1] = fss.SegPos + fss.SegLen
- } else {
- manifestForPath += fmt.Sprintf("%v", currentSpan[0]) + ":" + fmt.Sprintf("%v", currentSpan[1]+fss.SegLen) + ":" + fss.Name + " "
- currentSpan = []uint64{fss.SegPos, fss.SegPos + fss.SegLen}
- }
- }
- }
- manifestForPath += fmt.Sprintf("%v", currentSpan[0]) + ":" + fmt.Sprintf("%v", currentSpan[1]) + ":" + currentName + "\n"
- }
-
- return manifestForPath
-}
-
func (m *Manifest) StreamIter() <-chan ManifestStream {
ch := make(chan ManifestStream)
go func(input string) {