Merge branch '6203-locator-regexp' refs #6203 refs #6277
[arvados.git] / sdk / go / manifest / manifest.go
index 1227f4936fcf9a104a21aa6c41529dfe94570626..f6698c67d2f2436ff38b9e4c6f641e62f3b3110e 100644 (file)
@@ -21,20 +21,21 @@ type Manifest struct {
 }
 
 type BlockLocator struct {
-       Digest  blockdigest.BlockDigest
-       Size    int
-       Hints   []string
+       Digest blockdigest.BlockDigest
+       Size   int
+       Hints  []string
 }
 
-type ManifestLine struct {
-       StreamName  string
-       Blocks       []string
-       Files        []string
+// Represents a single line from a manifest.
+type ManifestStream struct {
+       StreamName string
+       Blocks     []string
+       Files      []string
 }
 
 func ParseBlockLocator(s string) (b BlockLocator, err error) {
        if !LocatorPattern.MatchString(s) {
-               err = fmt.Errorf("String \"%s\" does not match BlockLocator pattern " +
+               err = fmt.Errorf("String \"%s\" does not match BlockLocator pattern "+
                        "\"%s\".",
                        s,
                        LocatorPattern.String())
@@ -45,9 +46,13 @@ func ParseBlockLocator(s string) (b BlockLocator, err error) {
                // We expect both of the following to succeed since LocatorPattern
                // restricts the strings appropriately.
                blockDigest, err = blockdigest.FromString(tokens[0])
-               if err != nil {return}
+               if err != nil {
+                       return
+               }
                blockSize, err = strconv.ParseInt(tokens[1], 10, 0)
-               if err != nil {return}
+               if err != nil {
+                       return
+               }
                b.Digest = blockDigest
                b.Size = int(blockSize)
                b.Hints = tokens[2:]
@@ -55,7 +60,7 @@ func ParseBlockLocator(s string) (b BlockLocator, err error) {
        return
 }
 
-func parseManifestLine(s string) (m ManifestLine) {
+func parseManifestStream(s string) (m ManifestStream) {
        tokens := strings.Split(s, " ")
        m.StreamName = tokens[0]
        tokens = tokens[1:]
@@ -70,8 +75,8 @@ func parseManifestLine(s string) (m ManifestLine) {
        return
 }
 
-func (m *Manifest) LineIter() <-chan ManifestLine {
-       ch := make(chan ManifestLine)
+func (m *Manifest) StreamIter() <-chan ManifestStream {
+       ch := make(chan ManifestStream)
        go func(input string) {
                // This slice holds the current line and the remainder of the
                // manifest.  We parse one line at a time, to save effort if we
@@ -81,7 +86,7 @@ func (m *Manifest) LineIter() <-chan ManifestLine {
                        lines = strings.SplitN(lines[1], "\n", 2)
                        if len(lines[0]) > 0 {
                                // Only parse non-blank lines
-                               ch <- parseManifestLine(lines[0])
+                               ch <- parseManifestStream(lines[0])
                        }
                        if len(lines) == 1 {
                                break
@@ -92,14 +97,13 @@ func (m *Manifest) LineIter() <-chan ManifestLine {
        return ch
 }
 
-
 // Blocks may appear mulitple times within the same manifest if they
 // are used by multiple files. In that case this Iterator will output
 // the same block multiple times.
 func (m *Manifest) BlockIterWithDuplicates() <-chan BlockLocator {
        blockChannel := make(chan BlockLocator)
-       go func(lineChannel <-chan ManifestLine) {
-               for m := range lineChannel {
+       go func(streamChannel <-chan ManifestStream) {
+               for m := range streamChannel {
                        for _, block := range m.Blocks {
                                if b, err := ParseBlockLocator(block); err == nil {
                                        blockChannel <- b
@@ -109,6 +113,6 @@ func (m *Manifest) BlockIterWithDuplicates() <-chan BlockLocator {
                        }
                }
                close(blockChannel)
-       }(m.LineIter())
+       }(m.StreamIter())
        return blockChannel
 }