-
Notifications
You must be signed in to change notification settings - Fork 105
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
Reader support open db from embed.fs