BlobFromReader returns a new Blob from the provided Reader r, which should be the body of the provided blobref. Note: the hash checksum is not verified.
(ref blob.Ref, r io.Reader)
| 326 | // which should be the body of the provided blobref. |
| 327 | // Note: the hash checksum is not verified. |
| 328 | func BlobFromReader(ref blob.Ref, r io.Reader) (*Blob, error) { |
| 329 | if !ref.Valid() { |
| 330 | return nil, errors.New("schema.BlobFromReader: invalid blobref") |
| 331 | } |
| 332 | var buf bytes.Buffer |
| 333 | tee := io.TeeReader(r, &buf) |
| 334 | ss, err := parseSuperset(tee) |
| 335 | if err != nil { |
| 336 | return nil, fmt.Errorf("error parsing Blob %v: %w", ref, err) |
| 337 | } |
| 338 | return &Blob{ref, buf.String(), ss}, nil |
| 339 | } |
| 340 | |
| 341 | // BytesPart is the type representing one of the "parts" in a "file" |
| 342 | // or "bytes" JSON schema. |