You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
650 B
Go
43 lines
650 B
Go
package snapshot
|
|
|
|
import "io"
|
|
|
|
type Snapshot struct {
|
|
walData []byte
|
|
files []string
|
|
}
|
|
|
|
func NewWALSnapshot(b []byte) *Snapshot {
|
|
return &Snapshot{
|
|
walData: b,
|
|
}
|
|
}
|
|
|
|
func NewFullSnapshot(files ...string) *Snapshot {
|
|
return &Snapshot{
|
|
files: files,
|
|
}
|
|
}
|
|
|
|
func (s *Snapshot) Persist(sink *Sink) error {
|
|
stream, err := s.OpenStream()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer stream.Close()
|
|
|
|
_, err = io.Copy(sink, stream)
|
|
return err
|
|
}
|
|
|
|
func (s *Snapshot) Release() error {
|
|
return nil
|
|
}
|
|
|
|
func (s *Snapshot) OpenStream() (*Stream, error) {
|
|
if len(s.files) > 0 {
|
|
return NewFullStream(s.files...)
|
|
}
|
|
return NewIncrementalStream(s.walData)
|
|
}
|