mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 14:56:29 +00:00
Improve variable naming, remove unneeded typecasts
This commit is contained in:
parent
a40299fa24
commit
1b3d3a7ec2
32
pack/pack.go
32
pack/pack.go
@ -121,12 +121,11 @@ type headerEntry struct {
|
|||||||
// Returned are the complete number of bytes written, including the header.
|
// Returned are the complete number of bytes written, including the header.
|
||||||
// After Finalize() has finished, the ID of this pack can be obtained by
|
// After Finalize() has finished, the ID of this pack can be obtained by
|
||||||
// calling ID().
|
// calling ID().
|
||||||
func (p *Packer) Finalize() (int64, error) {
|
func (p *Packer) Finalize() (bytesWritten int64, err error) {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
|
|
||||||
// n tracks the number of bytes written for the header
|
bytesWritten = int64(p.bytes)
|
||||||
var n int64 = int64(p.bytes)
|
|
||||||
|
|
||||||
// create writer to encrypt header
|
// create writer to encrypt header
|
||||||
wr := crypto.EncryptTo(p.k, p.hw)
|
wr := crypto.EncryptTo(p.k, p.hw)
|
||||||
@ -142,31 +141,31 @@ func (p *Packer) Finalize() (int64, error) {
|
|||||||
err := binary.Write(wr, binary.LittleEndian, entry)
|
err := binary.Write(wr, binary.LittleEndian, entry)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wr.Close()
|
wr.Close()
|
||||||
return int64(n), err
|
return int64(bytesWritten), err
|
||||||
}
|
}
|
||||||
|
|
||||||
n += int64(entrySize)
|
bytesWritten += int64(entrySize)
|
||||||
}
|
}
|
||||||
|
|
||||||
// finalize encrypted header
|
// finalize encrypted header
|
||||||
err := wr.Close()
|
err = wr.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return int64(n), err
|
return int64(bytesWritten), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// account for crypto overhead
|
// account for crypto overhead
|
||||||
n += crypto.Extension
|
bytesWritten += crypto.Extension
|
||||||
|
|
||||||
// write length
|
// write length
|
||||||
err = binary.Write(p.hw, binary.LittleEndian, uint32(len(p.blobs)*entrySize+crypto.Extension))
|
err = binary.Write(p.hw, binary.LittleEndian, uint32(len(p.blobs)*entrySize+crypto.Extension))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return int64(n), err
|
return bytesWritten, err
|
||||||
}
|
}
|
||||||
n += int64(binary.Size(uint32(0)))
|
bytesWritten += int64(binary.Size(uint32(0)))
|
||||||
|
|
||||||
p.bytes = uint(n)
|
p.bytes = uint(bytesWritten)
|
||||||
|
|
||||||
return n, nil
|
return bytesWritten, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ID returns the ID of all data written so far.
|
// ID returns the ID of all data written so far.
|
||||||
@ -229,21 +228,20 @@ func NewUnpacker(k *crypto.Key, entries []Blob, rd io.ReadSeeker) (*Unpacker, er
|
|||||||
return nil, fmt.Errorf("seeking to read header length failed: %v", err)
|
return nil, fmt.Errorf("seeking to read header length failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// read length
|
var length uint32
|
||||||
var l uint32
|
err = binary.Read(rd, binary.LittleEndian, &length)
|
||||||
err = binary.Read(rd, binary.LittleEndian, &l)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("reading header length failed: %v", err)
|
return nil, fmt.Errorf("reading header length failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset to the beginning of the header
|
// reset to the beginning of the header
|
||||||
_, err = rd.Seek(-int64(ls)-int64(l), 2)
|
_, err = rd.Seek(-int64(ls)-int64(length), 2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("seeking to read header length failed: %v", err)
|
return nil, fmt.Errorf("seeking to read header length failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// read header
|
// read header
|
||||||
hrd, err := crypto.DecryptFrom(k, io.LimitReader(rd, int64(l)))
|
hrd, err := crypto.DecryptFrom(k, io.LimitReader(rd, int64(length)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user