mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-03 11:30:28 -05:00
c5964aadcd
This is in preparation for chunking
50 lines
720 B
Go
50 lines
720 B
Go
package types
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"io/ioutil"
|
|
|
|
"github.com/attic-labs/noms/dbg"
|
|
"github.com/attic-labs/noms/ref"
|
|
)
|
|
|
|
type Blob struct {
|
|
data []byte
|
|
ref *ref.Ref
|
|
}
|
|
|
|
func (fb Blob) Reader() io.Reader {
|
|
return bytes.NewBuffer(fb.data)
|
|
}
|
|
|
|
func (fb Blob) Len() uint64 {
|
|
return uint64(len(fb.data))
|
|
}
|
|
|
|
func (fb Blob) Ref() ref.Ref {
|
|
return ensureRef(fb.ref, fb)
|
|
}
|
|
|
|
func (fb Blob) Equals(other Value) bool {
|
|
if other == nil {
|
|
return false
|
|
} else {
|
|
return fb.Ref() == other.Ref()
|
|
}
|
|
}
|
|
|
|
func (fb Blob) Chunks() []Future {
|
|
return nil
|
|
}
|
|
|
|
func NewBlob(r io.Reader) Blob {
|
|
data, err := ioutil.ReadAll(r)
|
|
dbg.Chk.NoError(err)
|
|
return Blob{data, &ref.Ref{}}
|
|
}
|
|
|
|
func BlobFromVal(v Value) Blob {
|
|
return v.(Blob)
|
|
}
|