Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for wasm/wasip1 build without mmap support #110

Merged
merged 1 commit into from
Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading