pikpak: non-buffered hash calculation for local source files

This commit is contained in:
wiserain 2024-07-01 17:52:05 +09:00 committed by Nick Craig-Wood
parent 56caab2033
commit 846c1aeed0

View File

@ -1695,6 +1695,18 @@ func (o *Object) upload(ctx context.Context, in io.Reader, src fs.ObjectInfo, wi
// Calculate gcid; grabbed from package jottacloud // Calculate gcid; grabbed from package jottacloud
var gcid string var gcid string
if srcObj := fs.UnWrapObjectInfo(src); srcObj != nil && srcObj.Fs().Features().IsLocal {
// No buffering; directly calculate gcid from source
rc, err := srcObj.Open(ctx)
if err != nil {
return fmt.Errorf("failed to open src: %w", err)
}
defer fs.CheckClose(rc, &err)
if gcid, err = calcGcid(rc, srcObj.Size()); err != nil {
return fmt.Errorf("failed to calculate gcid: %w", err)
}
} else {
// unwrap the accounting from the input, we use wrap to put it // unwrap the accounting from the input, we use wrap to put it
// back on after the buffering // back on after the buffering
var wrap accounting.WrapFn var wrap accounting.WrapFn
@ -1707,6 +1719,7 @@ func (o *Object) upload(ctx context.Context, in io.Reader, src fs.ObjectInfo, wi
} }
// Wrap the accounting back onto the stream // Wrap the accounting back onto the stream
in = wrap(in) in = wrap(in)
}
if !withTemp { if !withTemp {
info, err := o.fs.upload(ctx, in, leaf, dirID, gcid, size, options...) info, err := o.fs.upload(ctx, in, leaf, dirID, gcid, size, options...)