Handle sparse files (fixes #245)
This commit is contained in:
@@ -5,7 +5,13 @@
|
||||
|
||||
package protocol
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var sha256OfEmptyBlock = sha256.Sum256(make([]byte, BlockSize))
|
||||
|
||||
type IndexMessage struct {
|
||||
Folder string // max:256
|
||||
@@ -98,6 +104,11 @@ func (b BlockInfo) String() string {
|
||||
return fmt.Sprintf("Block{%d/%d/%x}", b.Offset, b.Size, b.Hash)
|
||||
}
|
||||
|
||||
// IsEmpty returns true if the block is a full block of zeroes.
|
||||
func (b BlockInfo) IsEmpty() bool {
|
||||
return b.Size == BlockSize && bytes.Equal(b.Hash, sha256OfEmptyBlock[:])
|
||||
}
|
||||
|
||||
type RequestMessage struct {
|
||||
Folder string // max:256
|
||||
Name string // max:8192
|
||||
|
||||
Reference in New Issue
Block a user