Skip to content

Commit

Permalink
Merge pull request #110 from domainr/wasm
Browse files Browse the repository at this point in the history
add support for wasm/wasip1 build without mmap support
  • Loading branch information
oschwald committed Jun 18, 2023
2 parents 1c54c94 + 70dbcd7 commit 7d12b8c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 39 deletions.
4 changes: 2 additions & 2 deletions mmap_unix.go
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 1 addition & 0 deletions mmap_windows.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build windows && !appengine
// +build windows,!appengine

package maxminddb
Expand Down
28 changes: 0 additions & 28 deletions reader_appengine.go

This file was deleted.

26 changes: 26 additions & 0 deletions reader_memory.go
Original file line number Diff line number Diff line change
@@ -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
}
16 changes: 7 additions & 9 deletions reader_other.go → reader_mmap.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !appengine && !plan9
// +build !appengine,!plan9
//go:build !appengine && !plan9 && !js && !wasip1
// +build !appengine,!plan9,!js,!wasip1

package maxminddb

Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 7d12b8c

Please sign in to comment.