forked from wal-g/wal-g
/
stream_push_helper.go
44 lines (35 loc) · 1.21 KB
/
stream_push_helper.go
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
package internal
import (
"io"
"os"
"path"
"github.com/tinsane/tracelog"
"github.com/wal-g/wal-g/utility"
)
const (
StreamPrefix = "stream_"
)
// TODO : unit tests
// PushStream compresses a stream and push it
func (uploader *Uploader) PushStream(stream io.Reader) (string, error) {
backupName := StreamPrefix + utility.TimeNowCrossPlatformUTC().Format("20060102T150405Z")
dstPath := getStreamName(backupName, uploader.Compressor.FileExtension())
err := uploader.PushStreamToDestination(stream, dstPath)
return backupName, err
}
// TODO : unit tests
// PushStreamToDestination compresses a stream and push it to specifyed destination
func (uploader *Uploader) PushStreamToDestination(stream io.Reader, dstPath string) error {
compressed := CompressAndEncrypt(stream, uploader.Compressor, ConfigureCrypter())
err := uploader.Upload(dstPath, compressed)
tracelog.InfoLogger.Println("FILE PATH:", dstPath)
return err
}
// FileIsPiped Check if file is piped
func FileIsPiped(stream *os.File) bool {
stat, _ := stream.Stat()
return (stat.Mode() & os.ModeCharDevice) == 0
}
func getStreamName(backupName string, extension string) string {
return utility.SanitizePath(path.Join(backupName, "stream.")) + extension
}