mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-22 12:51:19 +08:00
last golint
This commit is contained in:
@ -34,12 +34,13 @@ func SplitterBySize(n int) BlockSplitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: this should take a reader, not a byte array. what if we're splitting a 3TB file?
|
// TODO: this should take a reader, not a byte array. what if we're splitting a 3TB file?
|
||||||
|
//Rabin Fingerprinting for file chunking
|
||||||
func Rabin(b []byte) [][]byte {
|
func Rabin(b []byte) [][]byte {
|
||||||
var out [][]byte
|
var out [][]byte
|
||||||
windowsize := uint64(48)
|
windowsize := uint64(48)
|
||||||
chunk_max := 1024 * 16
|
chunkMax := 1024 * 16
|
||||||
min_blk_size := 2048
|
minBlkSize := 2048
|
||||||
blk_beg_i := 0
|
blkBegI := 0
|
||||||
prime := uint64(61)
|
prime := uint64(61)
|
||||||
|
|
||||||
var poly uint64
|
var poly uint64
|
||||||
@ -63,21 +64,21 @@ func Rabin(b []byte) [][]byte {
|
|||||||
poly = (poly * prime) + cur
|
poly = (poly * prime) + cur
|
||||||
curchecksum -= (uint64(b[i-1]) * prime)
|
curchecksum -= (uint64(b[i-1]) * prime)
|
||||||
|
|
||||||
if i-blk_beg_i >= chunk_max {
|
if i-blkgBegI >= chunkMax {
|
||||||
// push block
|
// push block
|
||||||
out = append(out, b[blk_beg_i:i])
|
out = append(out, b[blkgBegI:i])
|
||||||
blk_beg_i = i
|
blkgBegI = i
|
||||||
}
|
}
|
||||||
|
|
||||||
// first 13 bits of polynomial are 0
|
// first 13 bits of polynomial are 0
|
||||||
if poly%8192 == 0 && i-blk_beg_i >= min_blk_size {
|
if poly%8192 == 0 && i-blkgBegI >= minBlkSize {
|
||||||
// push block
|
// push block
|
||||||
out = append(out, b[blk_beg_i:i])
|
out = append(out, b[blkgBegI:i])
|
||||||
blk_beg_i = i
|
blkgBegI = i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if i > blk_beg_i {
|
if i > blkgBegI {
|
||||||
out = append(out, b[blk_beg_i:])
|
out = append(out, b[blkgBegI:])
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
u "github.com/jbenet/go-ipfs/util"
|
u "github.com/jbenet/go-ipfs/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrIsDir = errors.New("this dag node is a directory.")
|
var ErrIsDir = errors.New("this dag node is a directory")
|
||||||
|
|
||||||
// DagReader provides a way to easily read the data contained in a dag.
|
// DagReader provides a way to easily read the data contained in a dag.
|
||||||
type DagReader struct {
|
type DagReader struct {
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
// ID is a byte slice representing the identity of a peer.
|
// ID is a byte slice representing the identity of a peer.
|
||||||
type ID mh.Multihash
|
type ID mh.Multihash
|
||||||
|
|
||||||
// Utililty function for comparing two peer ID's
|
// Equal is utililty function for comparing two peer ID's
|
||||||
func (id ID) Equal(other ID) bool {
|
func (id ID) Equal(other ID) bool {
|
||||||
return bytes.Equal(id, other)
|
return bytes.Equal(id, other)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user