Skip to content

Commit af17178

Browse files
committed
Remove deprecated FromBytes in favor of OpenBytes
1 parent 58b8530 commit af17178

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changes
22

3+
## 2.0.0 - 2025-10-18
4+
5+
- BREAKING CHANGE: Removed deprecated `FromBytes`. Use `OpenBytes` instead.
6+
37
## 2.0.0-beta.10 - 2025-08-23
48

59
- Replaced `runtime.SetFinalizer` with `runtime.AddCleanup` for resource

fuzz_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func FuzzDatabase(f *testing.F) {
2929
f.Add([]byte{})
3030

3131
f.Fuzz(func(_ *testing.T, data []byte) {
32-
reader, err := FromBytes(data)
32+
reader, err := OpenBytes(data)
3333
if err != nil {
3434
return
3535
}
@@ -74,7 +74,7 @@ func FuzzLookup(f *testing.F) {
7474
}
7575

7676
f.Fuzz(func(_ *testing.T, data []byte) {
77-
reader, err := FromBytes(data)
77+
reader, err := OpenBytes(data)
7878
if err != nil {
7979
return
8080
}
@@ -225,7 +225,7 @@ func FuzzNetworks(f *testing.F) {
225225
f.Add(bytes.Repeat([]byte{0xFF}, 512))
226226

227227
f.Fuzz(func(_ *testing.T, data []byte) {
228-
reader, err := FromBytes(data)
228+
reader, err := OpenBytes(data)
229229
if err != nil {
230230
return
231231
}

reader.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -366,14 +366,6 @@ func OpenBytes(buffer []byte, options ...ReaderOption) (*Reader, error) {
366366
return reader, nil
367367
}
368368

369-
// FromBytes takes a byte slice corresponding to a MaxMind DB file and any
370-
// options. It returns a Reader structure or an error.
371-
//
372-
// Deprecated: Use OpenBytes instead. FromBytes will be removed in a future version.
373-
func FromBytes(buffer []byte, options ...ReaderOption) (*Reader, error) {
374-
return OpenBytes(buffer, options...)
375-
}
376-
377369
// Lookup retrieves the database record for ip and returns a Result, which can
378370
// be used to decode the data.
379371
func (r *Reader) Lookup(ip netip.Addr) Result {

reader_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestReaderBytes(t *testing.T) {
5353
)
5454
bytes, err := os.ReadFile(fileName)
5555
require.NoError(t, err)
56-
reader, err := FromBytes(bytes)
56+
reader, err := OpenBytes(bytes)
5757
require.NoError(t, err, "unexpected error while opening bytes: %v", err)
5858

5959
checkMetadata(t, reader, ipVersion, recordSize)
@@ -1260,7 +1260,7 @@ func TestMetadataBuildTime(t *testing.T) {
12601260
}
12611261

12621262
func TestIntegerOverflowProtection(t *testing.T) {
1263-
// Test that FromBytes detects integer overflow in search tree size calculation
1263+
// Test that OpenBytes detects integer overflow in search tree size calculation
12641264
t.Run("NodeCount overflow protection", func(t *testing.T) {
12651265
// Create metadata that would cause overflow: very large NodeCount
12661266
// For a 64-bit system with RecordSize=32, this should trigger overflow
@@ -1289,14 +1289,14 @@ func TestIntegerOverflowProtection(t *testing.T) {
12891289

12901290
// Since we can't easily create an invalid MMDB file that parses but has overflow values,
12911291
// we test the core logic validation here and rely on integration tests
1292-
// for the full FromBytes flow
1292+
// for the full OpenBytes flow
12931293

12941294
if metadata.NodeCount > 0 && metadata.RecordSize > 0 {
12951295
recordSizeQuarter := metadata.RecordSize / 4
12961296
if recordSizeQuarter > 0 {
12971297
maxNodes := ^uint(0) / recordSizeQuarter
12981298
if metadata.NodeCount > maxNodes {
1299-
// This is what should happen in FromBytes
1299+
// This is what should happen in OpenBytes
13001300
err := mmdberrors.NewInvalidDatabaseError("database tree size would overflow")
13011301
assert.Equal(t, "database tree size would overflow", err.Error())
13021302
}

0 commit comments

Comments
 (0)