NewWriter returns a writer for writing the data of a BSUP object as well as optionally creating a seek index for the row object when the seekIndexStride is non-zero. We assume all records are non-volatile until Close as super.Values from the various record bodies are referenced across calls to Writ
(ctx context.Context, engine storage.Engine, path *storage.URI, sortKey order.SortKey, seekIndexStride int)
| 33 | // Close as super.Values from the various record bodies are referenced across |
| 34 | // calls to Write. |
| 35 | func (o *Object) NewWriter(ctx context.Context, engine storage.Engine, path *storage.URI, sortKey order.SortKey, seekIndexStride int) (*Writer, error) { |
| 36 | out, err := engine.Put(ctx, o.SequenceURI(path)) |
| 37 | if err != nil { |
| 38 | return nil, err |
| 39 | } |
| 40 | counter := &writeCounter{bufwriter.New(out), 0} |
| 41 | w := &Writer{ |
| 42 | object: o, |
| 43 | byteCounter: counter, |
| 44 | writer: bsupio.NewWriter(counter), |
| 45 | sortKey: sortKey, |
| 46 | first: true, |
| 47 | } |
| 48 | if seekIndexStride == 0 { |
| 49 | seekIndexStride = DefaultSeekStride |
| 50 | } |
| 51 | w.seekIndexStride = seekIndexStride |
| 52 | seekOut, err := engine.Put(ctx, o.SeekIndexURI(path)) |
| 53 | if err != nil { |
| 54 | return nil, err |
| 55 | } |
| 56 | w.seekIndex = seekindex.NewWriter(bsupio.NewWriter(bufwriter.New(seekOut))) |
| 57 | return w, nil |
| 58 | } |
| 59 | |
| 60 | func (w *Writer) Write(val super.Value) error { |
| 61 | key := val.DerefPath(w.sortKey.Key).MissingAsNull() |