Skip to content

Commit dd4a944

Browse files
committed
Add OpenBytes function and deprecate FromBytes
Replace FromBytes with OpenBytes for better API discoverability and consistency with Open(). FromBytes remains as deprecated alias.
1 parent de53e43 commit dd4a944

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
- Improved memory mapping implementation by using `SyscallConn()` instead of
2121
`Fd()` to avoid side effects and prepare for Go 1.25+ Windows I/O
2222
enhancements. Pull request by database64128. GitHub #179.
23+
- Added `OpenBytes` function for better API discoverability and consistency
24+
with `Open()`. `FromBytes` is now deprecated and will be removed in a future
25+
version.
2326

2427
## 2.0.0-beta.8 - 2025-07-15
2528

reader.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func (m Metadata) BuildTime() time.Time {
197197

198198
type readerOptions struct{}
199199

200-
// ReaderOption are options for [Open] and [FromBytes].
200+
// ReaderOption are options for [Open] and [OpenBytes].
201201
//
202202
// This was added to allow for future options, e.g., for caching, without
203203
// causing a breaking API change.
@@ -241,12 +241,12 @@ func Open(file string, options ...ReaderOption) (*Reader, error) {
241241
if err != nil {
242242
return nil, err
243243
}
244-
return FromBytes(data, options...)
244+
return OpenBytes(data, options...)
245245
}
246246
return nil, err
247247
}
248248

249-
reader, err := FromBytes(data, options...)
249+
reader, err := OpenBytes(data, options...)
250250
if err != nil {
251251
_ = munmap(data)
252252
return nil, err
@@ -290,9 +290,9 @@ func (r *Reader) Close() error {
290290
return err
291291
}
292292

293-
// FromBytes takes a byte slice corresponding to a MaxMind DB file and any
293+
// OpenBytes takes a byte slice corresponding to a MaxMind DB file and any
294294
// options. It returns a Reader structure or an error.
295-
func FromBytes(buffer []byte, options ...ReaderOption) (*Reader, error) {
295+
func OpenBytes(buffer []byte, options ...ReaderOption) (*Reader, error) {
296296
opts := &readerOptions{}
297297
for _, option := range options {
298298
option(opts)
@@ -353,6 +353,14 @@ func FromBytes(buffer []byte, options ...ReaderOption) (*Reader, error) {
353353
return reader, nil
354354
}
355355

356+
// FromBytes takes a byte slice corresponding to a MaxMind DB file and any
357+
// options. It returns a Reader structure or an error.
358+
//
359+
// Deprecated: Use OpenBytes instead. FromBytes will be removed in a future version.
360+
func FromBytes(buffer []byte, options ...ReaderOption) (*Reader, error) {
361+
return OpenBytes(buffer, options...)
362+
}
363+
356364
// Lookup retrieves the database record for ip and returns a Result, which can
357365
// be used to decode the data.
358366
func (r *Reader) Lookup(ip netip.Addr) Result {

0 commit comments

Comments
 (0)