-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmanifest.go
More file actions
65 lines (54 loc) · 1.57 KB
/
Copy pathmanifest.go
File metadata and controls
65 lines (54 loc) · 1.57 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
package feedx
import (
"context"
"errors"
"strconv"
"strings"
"github.com/bsm/bfs"
)
// manifest holds the current feed status.
// the current manifest is consumed before each push and a new manifest written after each push.
type manifest struct {
// Version holds the most recent version of the records included in Files.
Version int64 `json:"version"`
// Generation is a incrementing counter for use in file compaction.
Generation int `json:"generation"`
// Files holds a set of data files
Files []string `json:"files"`
}
func loadManifest(ctx context.Context, obj *bfs.Object) (*manifest, error) {
m := new(manifest)
r, err := NewReader(ctx, obj, nil)
if errors.Is(err, bfs.ErrNotFound) {
return m, nil
} else if err != nil {
return nil, err
}
defer func() { _ = r.Close() }()
if err := r.Decode(m); errors.Is(err, bfs.ErrNotFound) { // some BFS implementations defer Open-ing the S3 object till first Decode call
return m, nil
} else if err != nil {
return nil, err
}
return m, nil
}
func (m *manifest) newDataFileName(wopt *WriterOptions) string {
version := strings.ReplaceAll(strconv.FormatInt(wopt.Version, 10), ".", "")
formatExt := ".json"
switch wopt.Format {
case ProtobufFormat:
formatExt = ".pb"
case CBORFormat:
formatExt = ".cbor"
}
var compressionSuffix string
switch wopt.Compression {
case GZipCompression:
compressionSuffix = "z"
case FlateCompression:
compressionSuffix = ".flate"
case ZstdCompression:
compressionSuffix = ".zst"
}
return "data-" + strconv.Itoa(m.Generation) + "-" + version + formatExt + compressionSuffix
}