Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ for _, p := range doc.Packages {

`Parse` auto-detects the format. `Detect` returns just the type without a full parse, scanning JSON keys, the XML root, or the tag-value document header.

`Inspect` reads the type and specification version from an `io.Reader`. It stops once both values are known and skips unrelated JSON values without building the package model:

```go
file, _ := os.Open("bom.cdx.json")
defer file.Close()

metadata, err := sbom.Inspect(file)
if err != nil {
log.Fatal(err)
}
fmt.Println(metadata.Type, metadata.SpecVersion)
```

Packages with different document IDs or PURLs remain separate, even when their names and versions match. `AddPackage` replaces an entry only when its name, version, document ID, and set of PURLs match. `Package.PURL()` returns the first PURL; `Package.ExternalRefs` retains all declared references.

```go
Expand Down
18 changes: 18 additions & 0 deletions bench_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sbom

import (
"bytes"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -129,6 +130,23 @@ func BenchmarkDetect(b *testing.B) {
}
}

func BenchmarkInspect(b *testing.B) {
for _, f := range benchFixtures {
data := readFixture(b, f.path)
b.Run(f.name, func(b *testing.B) {
b.ReportAllocs()
b.SetBytes(int64(len(data)))
b.ResetTimer()
for range b.N {
_, benchmarkError = Inspect(bytes.NewReader(data))
}
if benchmarkError != nil {
b.Fatal(benchmarkError)
}
})
}
}

func BenchmarkPackagePURL(b *testing.B) {
doc := mustParseBenchmark(b, readFixture(b, "cyclonedx/juice-shop.cdx.json"))
b.Run(fmt.Sprintf("%d-pkgs", len(doc.Packages)), func(b *testing.B) {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/git-pkgs/sbom

go 1.26
go 1.27

toolchain go1.26.7
toolchain go1.27.3
Loading
Loading