Skip to content

Commit 7d12b8c

Browse files
authored
Merge pull request #110 from domainr/wasm
add support for wasm/wasip1 build without mmap support
2 parents 1c54c94 + 70dbcd7 commit 7d12b8c

File tree

5 files changed

+36
-39
lines changed

5 files changed

+36
-39
lines changed

mmap_unix.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build !windows && !appengine && !plan9
2-
// +build !windows,!appengine,!plan9
1+
//go:build !windows && !appengine && !plan9 && !js && !wasip1
2+
// +build !windows,!appengine,!plan9,!js,!wasip1
33

44
package maxminddb
55

mmap_windows.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build windows && !appengine
12
// +build windows,!appengine
23

34
package maxminddb

reader_appengine.go

-28
This file was deleted.

reader_memory.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//go:build appengine || plan9 || js || wasip1
2+
// +build appengine plan9 js wasip1
3+
4+
package maxminddb
5+
6+
import "io/ioutil"
7+
8+
// Open takes a string path to a MaxMind DB file and returns a Reader
9+
// structure or an error. The database file is opened using a memory map
10+
// on supported platforms. On platforms without memory map support, such
11+
// as WebAssembly or Google App Engine, the database is loaded into memory.
12+
// Use the Close method on the Reader object to return the resources to the system.
13+
func Open(file string) (*Reader, error) {
14+
bytes, err := ioutil.ReadFile(file)
15+
if err != nil {
16+
return nil, err
17+
}
18+
19+
return FromBytes(bytes)
20+
}
21+
22+
// Close returns the resources used by the database to the system.
23+
func (r *Reader) Close() error {
24+
r.buffer = nil
25+
return nil
26+
}

reader_other.go renamed to reader_mmap.go

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build !appengine && !plan9
2-
// +build !appengine,!plan9
1+
//go:build !appengine && !plan9 && !js && !wasip1
2+
// +build !appengine,!plan9,!js,!wasip1
33

44
package maxminddb
55

@@ -9,10 +9,10 @@ import (
99
)
1010

1111
// Open takes a string path to a MaxMind DB file and returns a Reader
12-
// structure or an error. The database file is opened using a memory map,
13-
// except on Google App Engine where mmap is not supported; there the database
14-
// is loaded into memory. Use the Close method on the Reader object to return
15-
// the resources to the system.
12+
// structure or an error. The database file is opened using a memory map
13+
// on supported platforms. On platforms without memory map support, such
14+
// as WebAssembly or Google App Engine, the database is loaded into memory.
15+
// Use the Close method on the Reader object to return the resources to the system.
1616
func Open(file string) (*Reader, error) {
1717
mapFile, err := os.Open(file)
1818
if err != nil {
@@ -51,9 +51,7 @@ func Open(file string) (*Reader, error) {
5151
return reader, nil
5252
}
5353

54-
// Close unmaps the database file from virtual memory and returns the
55-
// resources to the system. If called on a Reader opened using FromBytes
56-
// or Open on Google App Engine, this method does nothing.
54+
// Close returns the resources used by the database to the system.
5755
func (r *Reader) Close() error {
5856
var err error
5957
if r.hasMappedFile {

0 commit comments

Comments
 (0)