2015-01-09 07:19:32 +00:00
|
|
|
// Copyright (C) 2014 The Syncthing Authors.
|
|
|
|
//
|
2015-03-07 20:36:35 +00:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
// You can obtain one at http://mozilla.org/MPL/2.0/.
|
2015-01-09 07:19:32 +00:00
|
|
|
|
2015-01-12 13:50:30 +00:00
|
|
|
package db
|
2015-01-09 07:19:32 +00:00
|
|
|
|
2015-02-13 12:46:49 +00:00
|
|
|
import "github.com/syncthing/protocol"
|
2015-01-09 07:19:32 +00:00
|
|
|
|
|
|
|
type FileInfoTruncated struct {
|
2015-02-13 12:46:49 +00:00
|
|
|
protocol.FileInfo
|
|
|
|
ActualSize int64
|
2015-01-09 07:19:32 +00:00
|
|
|
}
|
|
|
|
|
2015-02-13 12:46:49 +00:00
|
|
|
func (f *FileInfoTruncated) UnmarshalXDR(bs []byte) error {
|
|
|
|
err := f.FileInfo.UnmarshalXDR(bs)
|
|
|
|
f.ActualSize = f.FileInfo.Size()
|
|
|
|
f.FileInfo.Blocks = nil
|
|
|
|
return err
|
2015-01-09 07:19:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f FileInfoTruncated) Size() int64 {
|
2015-02-13 12:46:49 +00:00
|
|
|
return f.ActualSize
|
2015-01-09 07:19:32 +00:00
|
|
|
}
|
|
|
|
|
2015-01-18 01:12:06 +00:00
|
|
|
func BlocksToSize(num int) int64 {
|
2015-01-09 07:19:32 +00:00
|
|
|
if num < 2 {
|
|
|
|
return protocol.BlockSize / 2
|
|
|
|
}
|
|
|
|
return int64(num-1)*protocol.BlockSize + protocol.BlockSize/2
|
|
|
|
}
|