From 3af96e50bd09a36167202e0f5e9fe8d310c70a3b Mon Sep 17 00:00:00 2001 From: Audrius Butkevicius Date: Sun, 23 Nov 2014 00:52:48 +0000 Subject: [PATCH] Use custom structure for /need calls (fixes #1001) Also, remove trimming by number of blocks as this no longer affects the size of the response. --- message.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/message.go b/message.go index 355050ca..9a96f80c 100644 --- a/message.go +++ b/message.go @@ -81,16 +81,19 @@ func (f FileInfoTruncated) String() string { f.Name, f.Flags, f.Modified, f.Version, f.Size(), f.NumBlocks) } +func BlocksToSize(num uint32) int64 { + if num < 2 { + return BlockSize / 2 + } + return int64(num-1)*BlockSize + BlockSize/2 +} + // Returns a statistical guess on the size, not the exact figure func (f FileInfoTruncated) Size() int64 { if f.IsDeleted() || f.IsDirectory() { return 128 } - if f.NumBlocks < 2 { - return BlockSize / 2 - } else { - return int64(f.NumBlocks-1)*BlockSize + BlockSize/2 - } + return BlocksToSize(f.NumBlocks) } func (f FileInfoTruncated) IsDeleted() bool {