| 1 | /* |
| 2 | Copyright The ORAS Authors. |
| 3 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | you may not use this file except in compliance with the License. |
| 5 | You may obtain a copy of the License at |
| 6 | |
| 7 | http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | |
| 9 | Unless required by applicable law or agreed to in writing, software |
| 10 | distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | See the License for the specific language governing permissions and |
| 13 | limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | package contentscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/content`/ |
| 17 | |
| 18 | import ( |
| 19 | "github.com/opencontainers/go-digestscip-go gomod github.com/opencontainers/go-digest v1.0.0 `github.com/opencontainers/go-digest`/" |
| 20 | ocispecscip-go gomod github.com/opencontainers/image-spec v1.1.1 `github.com/opencontainers/image-spec/specs-go/v1`/ "github.com/opencontainers/image-spec/specs-go/v1scip-go gomod github.com/opencontainers/image-spec v1.1.1 `github.com/opencontainers/image-spec/specs-go/v1`/" |
| 21 | "oras.land/oras-go/v2/internal/descriptorscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/internal/descriptor`/" |
| 22 | ) |
| 23 | |
| 24 | // NewDescriptorFromBytes returns a descriptor, given the content and media type. |
| 25 | // If no media type is specified, "application/octet-stream" will be used. |
| 26 | func NewDescriptorFromBytesscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/content`/NewDescriptorFromBytes().(mediaType string, content []byte) ocispecscip-go gomod github.com/opencontainers/image-spec v1.1.1 `github.com/opencontainers/image-spec/specs-go/v1`/.Descriptorscip-go gomod github.com/opencontainers/image-spec v1.1.1 `github.com/opencontainers/image-spec/specs-go/v1`/Descriptor# { |
| 27 | if mediaType == "" { |
| 28 | mediaType = descriptorscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/internal/descriptor`/.DefaultMediaTypescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/internal/descriptor`/DefaultMediaType. |
| 29 | } |
| 30 | return ocispecscip-go gomod github.com/opencontainers/image-spec v1.1.1 `github.com/opencontainers/image-spec/specs-go/v1`/.Descriptorscip-go gomod github.com/opencontainers/image-spec v1.1.1 `github.com/opencontainers/image-spec/specs-go/v1`/Descriptor#{ |
| 31 | MediaTypescip-go gomod github.com/opencontainers/image-spec v1.1.1 `github.com/opencontainers/image-spec/specs-go/v1`/Descriptor#MediaType.: mediaType, |
| 32 | Digestscip-go gomod github.com/opencontainers/image-spec v1.1.1 `github.com/opencontainers/image-spec/specs-go/v1`/Descriptor#Digest.: digestscip-go gomod github.com/opencontainers/go-digest v1.0.0 `github.com/opencontainers/go-digest`/.FromBytesscip-go gomod github.com/opencontainers/go-digest v1.0.0 `github.com/opencontainers/go-digest`/FromBytes().(content), |
| 33 | Sizescip-go gomod github.com/opencontainers/image-spec v1.1.1 `github.com/opencontainers/image-spec/specs-go/v1`/Descriptor#Size.: int64(len(content)), |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | // Equal returns true if two descriptors point to the same content. |
| 38 | func Equalscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/content`/Equal().(a, b ocispecscip-go gomod github.com/opencontainers/image-spec v1.1.1 `github.com/opencontainers/image-spec/specs-go/v1`/.Descriptorscip-go gomod github.com/opencontainers/image-spec v1.1.1 `github.com/opencontainers/image-spec/specs-go/v1`/Descriptor#) bool { |
| 39 | return a.Sizescip-go gomod github.com/opencontainers/image-spec v1.1.1 `github.com/opencontainers/image-spec/specs-go/v1`/Descriptor#Size. == b.Sizescip-go gomod github.com/opencontainers/image-spec v1.1.1 `github.com/opencontainers/image-spec/specs-go/v1`/Descriptor#Size. && a.Digestscip-go gomod github.com/opencontainers/image-spec v1.1.1 `github.com/opencontainers/image-spec/specs-go/v1`/Descriptor#Digest. == b.Digestscip-go gomod github.com/opencontainers/image-spec v1.1.1 `github.com/opencontainers/image-spec/specs-go/v1`/Descriptor#Digest. && a.MediaTypescip-go gomod github.com/opencontainers/image-spec v1.1.1 `github.com/opencontainers/image-spec/specs-go/v1`/Descriptor#MediaType. == b.MediaTypescip-go gomod github.com/opencontainers/image-spec v1.1.1 `github.com/opencontainers/image-spec/specs-go/v1`/Descriptor#MediaType. |
| 40 | } |