mirror of
https://github.com/anchore/syft.git
synced 2026-11-04 00:16:38 +01:00
swap format readseekers for readers (#2515)
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/anchore/syft/internal/log"
|
||||
"github.com/anchore/syft/syft/format/common/cyclonedxhelpers"
|
||||
"github.com/anchore/syft/syft/format/internal/cyclonedxutil"
|
||||
"github.com/anchore/syft/syft/format/internal/stream"
|
||||
"github.com/anchore/syft/syft/sbom"
|
||||
)
|
||||
|
||||
@@ -26,9 +27,10 @@ func NewFormatDecoder() sbom.FormatDecoder {
|
||||
}
|
||||
}
|
||||
|
||||
func (d decoder) Decode(reader io.ReadSeeker) (*sbom.SBOM, sbom.FormatID, string, error) {
|
||||
if reader == nil {
|
||||
return nil, "", "", fmt.Errorf("no SBOM bytes provided")
|
||||
func (d decoder) Decode(r io.Reader) (*sbom.SBOM, sbom.FormatID, string, error) {
|
||||
reader, err := stream.SeekableReader(r)
|
||||
if err != nil {
|
||||
return nil, "", "", err
|
||||
}
|
||||
|
||||
id, version := d.Identify(reader)
|
||||
@@ -52,8 +54,9 @@ func (d decoder) Decode(reader io.ReadSeeker) (*sbom.SBOM, sbom.FormatID, string
|
||||
return s, id, version, nil
|
||||
}
|
||||
|
||||
func (d decoder) Identify(reader io.ReadSeeker) (sbom.FormatID, string) {
|
||||
if reader == nil {
|
||||
func (d decoder) Identify(r io.Reader) (sbom.FormatID, string) {
|
||||
reader, err := stream.SeekableReader(r)
|
||||
if err != nil {
|
||||
return "", ""
|
||||
}
|
||||
|
||||
@@ -69,8 +72,7 @@ func (d decoder) Identify(reader io.ReadSeeker) (sbom.FormatID, string) {
|
||||
dec := xml.NewDecoder(reader)
|
||||
|
||||
var doc Document
|
||||
err := dec.Decode(&doc)
|
||||
if err != nil {
|
||||
if err = dec.Decode(&doc); err != nil {
|
||||
// maybe not xml? maybe not valid? doesn't matter, we won't process it.
|
||||
return "", ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user