feat(backend/storage):split files into 2
This commit is contained in:
parent
0bbf8012f1
commit
1e5deed0d5
1 changed files with 27 additions and 2 deletions
|
|
@ -6,6 +6,10 @@ import (
|
|||
"strconv"
|
||||
"time"
|
||||
|
||||
"bytes"
|
||||
"io"
|
||||
"ioutill"
|
||||
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
|
|
@ -18,6 +22,8 @@ import (
|
|||
|
||||
const RetryTimeout = 2 * time.Minute
|
||||
|
||||
const SESSION_FILE_SPLIT_SIZE = 200000 // ~200 kB
|
||||
|
||||
func main() {
|
||||
log.SetFlags(log.LstdFlags | log.LUTC | log.Llongfile)
|
||||
|
||||
|
|
@ -41,8 +47,27 @@ func main() {
|
|||
}
|
||||
defer file.Close()
|
||||
|
||||
if err := storage.Upload(gzipFile(file), key, "application/octet-stream", true); err != nil {
|
||||
log.Fatalf("Storage upload error: %v\n", err)
|
||||
fileR2 := new(bytes.Buffer)
|
||||
fileR1 := io.TeeReader(file, fileR2)
|
||||
|
||||
startBytes := make([]byte, SESSION_FILE_SPLIT_SIZE)
|
||||
nRead, err := fileR1.Read(startBytes)
|
||||
if err != nil {
|
||||
log.Printf("File read error: %f", err)
|
||||
return
|
||||
}
|
||||
startReader = bytes.NewBuffer(startBytes)
|
||||
if err := storage.Upload(gzipFile(startReader), key+"-s", "application/octet-stream", true); err != nil {
|
||||
log.Fatalf("Storage: start upload failed. %v\n", err)
|
||||
}
|
||||
if nRead == SESSION_FILE_SPLIT_SIZE {
|
||||
if err := storage.Upload(gzipFile(fileR1), key+"-e", "application/octet-stream", true); err != nil {
|
||||
log.Fatalf("Storage: end upload failed. %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := storage.Upload(gzipFile(fileR2), key, "application/octet-stream", true); err != nil {
|
||||
log.Fatalf("Storage: upload failed. %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue