mirror of
https://github.com/lionsoul2014/ip2region.git
synced 2025-12-08 19:25:22 +00:00
auto close the handle after buffer loaded
This commit is contained in:
parent
680624db65
commit
c5fad74d95
@ -76,7 +76,13 @@ func LoadHeaderFromFile(dbFile string) (*Header, error) {
|
||||
return nil, fmt.Errorf("open xdb file `%s`: %w", dbFile, err)
|
||||
}
|
||||
|
||||
return LoadHeader(handle)
|
||||
header, err := LoadHeader(handle)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_ = handle.Close()
|
||||
return header, nil
|
||||
}
|
||||
|
||||
// LoadHeaderFromBuff wrap the header info from the content buffer
|
||||
@ -112,7 +118,13 @@ func LoadVectorIndexFromFile(dbFile string) ([]byte, error) {
|
||||
return nil, fmt.Errorf("open xdb file `%s`: %w", dbFile, err)
|
||||
}
|
||||
|
||||
return LoadVectorIndex(handle)
|
||||
vIndex, err := LoadVectorIndex(handle)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_ = handle.Close()
|
||||
return vIndex, nil
|
||||
}
|
||||
|
||||
// LoadContent load the whole xdb content from the specified file handle
|
||||
@ -151,5 +163,11 @@ func LoadContentFromFile(dbFile string) ([]byte, error) {
|
||||
return nil, fmt.Errorf("open xdb file `%s`: %w", dbFile, err)
|
||||
}
|
||||
|
||||
return LoadContent(handle)
|
||||
cBuff, err := LoadContent(handle)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_ = handle.Close()
|
||||
return cBuff, nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user