mirror of
https://github.com/octoleo/restic.git
synced 2024-12-22 19:08:55 +00:00
azure: explicitly pass upload size
Previously the fallback from the azure library was to read the whole blob into memory and use that to determine the upload size.
This commit is contained in:
parent
43cb26010a
commit
dca9b6f5db
@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
@ -118,6 +117,16 @@ func (be *Backend) Path() string {
|
||||
return be.prefix
|
||||
}
|
||||
|
||||
type azureAdapter struct {
|
||||
restic.RewindReader
|
||||
}
|
||||
|
||||
func (azureAdapter) Close() error { return nil }
|
||||
|
||||
func (a *azureAdapter) Len() int {
|
||||
return int(a.Length())
|
||||
}
|
||||
|
||||
// Save stores data in the backend at the handle.
|
||||
func (be *Backend) Save(ctx context.Context, h restic.Handle, rd restic.RewindReader) error {
|
||||
if err := h.Valid(); err != nil {
|
||||
@ -135,7 +144,8 @@ func (be *Backend) Save(ctx context.Context, h restic.Handle, rd restic.RewindRe
|
||||
var err error
|
||||
if rd.Length() < 256*1024*1024 {
|
||||
// wrap the reader so that net/http client cannot close the reader
|
||||
dataReader := ioutil.NopCloser(rd)
|
||||
// CreateBlockBlobFromReader reads length from `Len()``
|
||||
dataReader := azureAdapter{rd}
|
||||
|
||||
// if it's smaller than 256miB, then just create the file directly from the reader
|
||||
err = be.container.GetBlobReference(objName).CreateBlockBlobFromReader(dataReader, nil)
|
||||
|
Loading…
Reference in New Issue
Block a user