Skip to content

Commit 775e806

Browse files
committed
update
1 parent a58efd1 commit 775e806

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

city.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ func NewCity(name string) (*City, error) {
7474
}, nil
7575
}
7676

77+
func NewCityFromBytes(bs []byte) (*City, error) {
78+
r, e := newReaderFromBytes(bs, &CityInfo{})
79+
if e != nil {
80+
return nil, e
81+
}
82+
83+
return &City{reader: r}, nil
84+
}
85+
7786
// Reload the database
7887
func (db *City) Reload(name string) error {
7988

reader.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ func newReader(name string, obj interface{}) (*reader, error) {
6767
if err != nil {
6868
return nil, ErrReadFull
6969
}
70+
71+
return initBytes(body, fileSize, obj)
72+
}
73+
74+
func newReaderFromBytes(body []byte, obj interface{}) (*reader, error) {
75+
if len(body) < 4 {
76+
return nil, ErrFileSize
77+
}
78+
return initBytes(body, len(body), obj)
79+
}
80+
81+
func initBytes(body []byte, fileSize int, obj interface{}) (*reader, error) {
7082
var meta MetaData
7183
metaLength := int(binary.BigEndian.Uint32(body[0:4]))
7284
if fileSize < (4 + metaLength) {

0 commit comments

Comments
 (0)