diff --git a/mmap_unix.go b/mmap_unix.go index eeb2e05..5f6d80f 100644 --- a/mmap_unix.go +++ b/mmap_unix.go @@ -1,5 +1,5 @@ -//go:build !windows && !appengine && !plan9 -// +build !windows,!appengine,!plan9 +//go:build !windows && !appengine && !plan9 && !js && !wasip1 +// +build !windows,!appengine,!plan9,!js,!wasip1 package maxminddb diff --git a/mmap_windows.go b/mmap_windows.go index 661250e..79133a7 100644 --- a/mmap_windows.go +++ b/mmap_windows.go @@ -1,3 +1,4 @@ +//go:build windows && !appengine // +build windows,!appengine package maxminddb diff --git a/reader_appengine.go b/reader_appengine.go deleted file mode 100644 index c6385d8..0000000 --- a/reader_appengine.go +++ /dev/null @@ -1,28 +0,0 @@ -// +build appengine plan9 - -package maxminddb - -import "io/ioutil" - -// Open takes a string path to a MaxMind DB file and returns a Reader -// structure or an error. The database file is opened using a memory map, -// except on Google App Engine where mmap is not supported; there the database -// is loaded into memory. Use the Close method on the Reader object to return -// the resources to the system. -func Open(file string) (*Reader, error) { - bytes, err := ioutil.ReadFile(file) - if err != nil { - return nil, err - } - - return FromBytes(bytes) -} - -// Close unmaps the database file from virtual memory and returns the -// resources to the system. If called on a Reader opened using FromBytes -// or Open on Google App Engine, this method sets the underlying buffer -// to nil, returning the resources to the system. -func (r *Reader) Close() error { - r.buffer = nil - return nil -} diff --git a/reader_memory.go b/reader_memory.go new file mode 100644 index 0000000..33f1192 --- /dev/null +++ b/reader_memory.go @@ -0,0 +1,26 @@ +//go:build appengine || plan9 || js || wasip1 +// +build appengine plan9 js wasip1 + +package maxminddb + +import "io/ioutil" + +// Open takes a string path to a MaxMind DB file and returns a Reader +// structure or an error. The database file is opened using a memory map +// on supported platforms. On platforms without memory map support, such +// as WebAssembly or Google App Engine, the database is loaded into memory. +// Use the Close method on the Reader object to return the resources to the system. +func Open(file string) (*Reader, error) { + bytes, err := ioutil.ReadFile(file) + if err != nil { + return nil, err + } + + return FromBytes(bytes) +} + +// Close returns the resources used by the database to the system. +func (r *Reader) Close() error { + r.buffer = nil + return nil +} diff --git a/reader_other.go b/reader_mmap.go similarity index 70% rename from reader_other.go rename to reader_mmap.go index 0ed9de1..320d193 100644 --- a/reader_other.go +++ b/reader_mmap.go @@ -1,5 +1,5 @@ -//go:build !appengine && !plan9 -// +build !appengine,!plan9 +//go:build !appengine && !plan9 && !js && !wasip1 +// +build !appengine,!plan9,!js,!wasip1 package maxminddb @@ -9,10 +9,10 @@ import ( ) // Open takes a string path to a MaxMind DB file and returns a Reader -// structure or an error. The database file is opened using a memory map, -// except on Google App Engine where mmap is not supported; there the database -// is loaded into memory. Use the Close method on the Reader object to return -// the resources to the system. +// structure or an error. The database file is opened using a memory map +// on supported platforms. On platforms without memory map support, such +// as WebAssembly or Google App Engine, the database is loaded into memory. +// Use the Close method on the Reader object to return the resources to the system. func Open(file string) (*Reader, error) { mapFile, err := os.Open(file) if err != nil { @@ -51,9 +51,7 @@ func Open(file string) (*Reader, error) { return reader, nil } -// Close unmaps the database file from virtual memory and returns the -// resources to the system. If called on a Reader opened using FromBytes -// or Open on Google App Engine, this method does nothing. +// Close returns the resources used by the database to the system. func (r *Reader) Close() error { var err error if r.hasMappedFile {