Merge pull request #5177 from filecoin-project/acautman-iosize

stores: Bigger copy buffer size
This commit is contained in:
Łukasz Magiera 2020-12-10 22:28:47 +01:00 committed by GitHub
commit 65b921c62c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@ package stores
import (
"context"
"encoding/json"
"io"
"io/ioutil"
"math/bits"
"mime"
@ -22,12 +23,13 @@ import (
"github.com/filecoin-project/specs-storage/storage"
"github.com/hashicorp/go-multierror"
files "github.com/ipfs/go-ipfs-files"
"golang.org/x/xerrors"
)
var FetchTempSubdir = "fetching"
var CopyBuf = 1 << 20
type Remote struct {
local *Local
index SectorIndex
@ -276,7 +278,16 @@ func (r *Remote) fetch(ctx context.Context, url, outname string) error {
case "application/x-tar":
return tarutil.ExtractTar(resp.Body, outname)
case "application/octet-stream":
return files.WriteTo(files.NewReaderFile(resp.Body), outname)
f, err := os.Create(outname)
if err != nil {
return err
}
_, err = io.CopyBuffer(f, resp.Body, make([]byte, CopyBuf))
if err != nil {
f.Close() // nolint
return err
}
return f.Close()
default:
return xerrors.Errorf("unknown content type: '%s'", mediatype)
}