Skip to content

feat: Reader support open db from embed.fs #173

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dcboy
Copy link

@dcboy dcboy commented Apr 29, 2025

Reader support open db from embed.fs

Copy link
Owner

@oschwald oschwald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really see the point of adding a helper function for this. You end up saving a single ReadFile line plus whatever error handling your application needs. This change also hides that fact that you are just reading the bytes into memory and then opening that.


reader, err := FromBytes(data)
if err != nil {
_ = munmap(data)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no memory map. It doesn't make sense to cal this.

return nil, err
}

reader.hasMappedFile = true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are loading the file into memory, not memory mapping it.

}

reader.hasMappedFile = true
runtime.SetFinalizer(reader, (*Reader).Close)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no point is setting a finalizer here.

@@ -48,6 +49,23 @@ type Metadata struct {
RecordSize uint `maxminddb:"record_size"`
}

func OpenWithEmbedFS(f embed.FS, path string) (*Reader, error) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would need documentation and the name is somewhat awkward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants