예제 #1
0
func UploadStream(block1, block2 []byte, rand, src io.Reader, bck bucket.Bucket, tupleSize int, depth int) (broken bool, rest int, tuple [][]byte, e error) {
	broken = false
	hdr := blockheader.NewHeader()
	descr := &descriptor.DescriptorBlock{Header: hdr}
	hdr.TupleSize = tupleSize
	i := 0
	if depth <= 1 {
		for (i + tupleSize) <= MaxHashes {
			readed, tuple, e := GenerateTuple(block1, block2, rand, src, bck, tupleSize)
			if e != nil {
				return false, 0, nil, e
			}
			descr.AddBlock(tuple)
			i += tupleSize
			rest = readed
			if readed < BlockSize {
				broken = true
				break
			}
		}
	} else {
		for (i + tupleSize) <= MaxHashes {
			broken2, rest2, tuple2, e2 := UploadStream(block1, block2, rand, src, bck, tupleSize, depth-1)
			if e2 != nil {
				return false, 0, nil, e2
			}
			descr.AddBlock(tuple2)
			i += tupleSize
			rest = rest2
			if broken2 || rest2 < BlockSize {
				broken = true
				break
			}
		}
	}
	if len(descr.Tuples) == 1 {
		tuple = descr.Tuples[0]
		return
	}
	descr.UpdateHeader()
	if !descr.Serialize(rand, block1) {
		return broken, 0, nil, errors.New("serialisation-error")
	}
	tuple, e = GenerateTupleFromBlock(block1, block2, rand, bck, tupleSize)
	return
}
예제 #2
0
// This is a simple update function. It doesnt create ddblocks (Descriptors of Descriptors).
func UploadStreamSimple(block1, block2 []byte, rand, src io.Reader, bck bucket.Bucket, tupleSize int) (rest int, tuple [][]byte, e error) {
	hdr := blockheader.NewHeader()
	descr := &descriptor.DescriptorBlock{Header: hdr}
	hdr.TupleSize = tupleSize
	i := 0
	for (i + tupleSize) <= MaxHashes {
		readed, tuple, e := GenerateTuple(block1, block2, rand, src, bck, tupleSize)
		if e != nil {
			return 0, nil, e
		}
		descr.AddBlock(tuple)
		i += tupleSize
		rest = readed
		if readed < BlockSize {
			break
		}
	}
	descr.UpdateHeader()
	if !descr.Serialize(rand, block1) {
		return 0, nil, errors.New("serialisation-error")
	}
	tuple, e = GenerateTupleFromBlock(block1, block2, rand, bck, tupleSize)
	return
}