Exemplo n.º 1
0
func (ccs *hasCachingChunkStore) Put(c chunks.Chunk) {
	r := c.Ref()
	has, _ := checkCache(ccs, r)
	if has {
		return
	}
	ccs.backing.Put(c)
	setCache(ccs, r, true)
}
Exemplo n.º 2
0
// DecodeChunk decodes a value from a chunk source. It is not considered an error for the requested chunk to be empty; in this case, the function simply returns nil.
func DecodeChunk(c chunks.Chunk, vr ValueReader) Value {
	if c.IsEmpty() {
		return nil
	}

	v := decode(bytes.NewReader(c.Data()))

	switch v := v.(type) {
	case io.Reader:
		data, err := ioutil.ReadAll(v)
		d.Chk.NoError(err)
		return newBlobLeaf(data)
	case []interface{}:
		return fromTypedEncodeable(v, vr)
	}
	panic("Unreachable")
}