truncated.go 774 B

1234567891011121314151617181920212223242526272829303132
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at http://mozilla.org/MPL/2.0/.
  6. package db
  7. import "github.com/syncthing/syncthing/lib/protocol"
  8. type FileInfoTruncated struct {
  9. protocol.FileInfo
  10. ActualSize int64
  11. }
  12. func (f *FileInfoTruncated) UnmarshalXDR(bs []byte) error {
  13. err := f.FileInfo.UnmarshalXDR(bs)
  14. f.ActualSize = f.FileInfo.Size()
  15. f.FileInfo.Blocks = nil
  16. return err
  17. }
  18. func (f FileInfoTruncated) Size() int64 {
  19. return f.ActualSize
  20. }
  21. func BlocksToSize(num int) int64 {
  22. if num < 2 {
  23. return protocol.BlockSize / 2
  24. }
  25. return int64(num-1)*protocol.BlockSize + protocol.BlockSize/2
  26. }