aboutsummaryrefslogtreecommitdiff
path: root/zhead
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-07-17 14:10:11 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-07-17 14:10:11 +0200
commit0a2aacf3fd8fc8be274df82f264bd38974bd61f9 (patch)
treed396cfb4e6fc121d9fdb991dbaf7ab80b12aadc0 /zhead
parent4b7ed3d169dd0b4ce40f2a17cc049c055d5ba7a3 (diff)
bikeshadding
Diffstat (limited to 'zhead')
-rw-r--r--zhead/header.go28
1 files changed, 11 insertions, 17 deletions
diff --git a/zhead/header.go b/zhead/header.go
index 995f161..76f17bc 100644
--- a/zhead/header.go
+++ b/zhead/header.go
@@ -3,7 +3,6 @@ package zhead
import (
"bufio"
"encoding/hex"
- "errors"
"fmt"
"io"
"strconv"
@@ -37,11 +36,10 @@ func (h Header) Print(w io.Writer) error {
}
func Parse(r io.Reader) (Header, error) {
- var inSum bool
var h Header
- scanner := bufio.NewScanner(r)
- for scanner.Scan() {
- line := scanner.Text()
+ s := bufio.NewScanner(r)
+ for s.Scan() {
+ line := s.Text()
switch {
case strings.HasPrefix(line, "date="):
t, err := time.Parse(time.RFC3339, line[5:])
@@ -60,19 +58,15 @@ func Parse(r io.Reader) (Header, error) {
}
h.BlockSize = i
case line == "":
- if inSum {
- return Header{}, errors.New("already in sum part")
+ for s.Scan() {
+ line = s.Text()
+ sum, err := hex.DecodeString(line)
+ if err != nil {
+ return Header{}, err
+ }
+ h.Sums = append(h.Sums, sum)
}
- inSum = true
- continue
- }
- if inSum {
- sum, err := hex.DecodeString(line)
- if err != nil {
- return Header{}, err
- }
- h.Sums = append(h.Sums, sum)
}
}
- return h, scanner.Err()
+ return h, s.Err()
}