WriteUserIndex uploads the provided index to the storage.
(ctx context.Context, bkt objstore.Bucket, idx *UserIndex)
| 40 | |
| 41 | // WriteUserIndex uploads the provided index to the storage. |
| 42 | func WriteUserIndex(ctx context.Context, bkt objstore.Bucket, idx *UserIndex) error { |
| 43 | // Marshal the index. |
| 44 | content, err := json.Marshal(idx) |
| 45 | if err != nil { |
| 46 | return errors.Wrap(err, "marshal user index") |
| 47 | } |
| 48 | |
| 49 | // Compress it. |
| 50 | var gzipContent bytes.Buffer |
| 51 | gzip := gzip.NewWriter(&gzipContent) |
| 52 | gzip.Name = UserIndexFilename |
| 53 | |
| 54 | if _, err := gzip.Write(content); err != nil { |
| 55 | return errors.Wrap(err, "gzip user index") |
| 56 | } |
| 57 | if err := gzip.Close(); err != nil { |
| 58 | return errors.Wrap(err, "close gzip user index") |
| 59 | } |
| 60 | |
| 61 | // Upload the index to the storage. |
| 62 | if err := bkt.Upload(ctx, UserIndexCompressedFilename, bytes.NewReader(gzipContent.Bytes())); err != nil { |
| 63 | return errors.Wrap(err, "upload user index") |
| 64 | } |
| 65 | |
| 66 | return nil |
| 67 | } |
| 68 | |
| 69 | func ReadUserIndex(ctx context.Context, bkt objstore.InstrumentedBucket, logger log.Logger) (*UserIndex, error) { |
| 70 | // Get the user index. |