-
Notifications
You must be signed in to change notification settings - Fork 68
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
Added support to load from memory #36
base: master
Are you sure you want to change the base?
Conversation
@@ -53,6 +75,17 @@ func Open(filename string) (*Reader, error) { | |||
return s, nil | |||
} | |||
|
|||
func OpenFromMemory(shpFileData, dbfFileData []byte) (*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.
exported function OpenFromMemory should have comment or be unexported
Codecov Report
@@ Coverage Diff @@
## master #36 +/- ##
==========================================
+ Coverage 60.04% 60.17% +0.12%
==========================================
Files 7 7
Lines 801 816 +15
==========================================
+ Hits 481 491 +10
- Misses 264 269 +5
Partials 56 56
Continue to review full report at Codecov.
|
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.
Thank you for your PR. I understand that you want to read shapefiles and attributes from data embedded in the executable.
To be honest, the proposed solution feels too "hacky" for me. I am sure that it works, but I'm afraid this could be hard to maintain in the long run.
I'd rather you'd open up an issue to discuss a design. I'd also be interested to get more minds on this.
@@ -30,6 +31,8 @@ type Reader struct { | |||
dbfNumRecords int32 | |||
dbfHeaderLength int16 | |||
dbfRecordLength int16 | |||
|
|||
memoryData *memoryShapeData |
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'm not happy with adding this member variable to the struct.
Do you need to have random access? If not, have you considered https://godoc.org/github.com/jonas-p/go-shp#SequentialReaderFromExt for opening the byte slices?
r.dbf, err = os.Open(r.filename + ".dbf") | ||
if err != nil { | ||
return | ||
if r.memoryData != nil { |
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.
IMHO this is a bit of a code smell: Testing whether one of the members is holding data and then branching the logic from there.
dbfFileData: dbfFileData, | ||
} | ||
|
||
s := &Reader{filename: "", shp: newBytesReader(mD.shpFileData), memoryData: mD} |
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 have doubts about this, as well. Effectively, you are adding references to mD
twice to s
. I understand that you want to preserve the dbf data so that openDbf has something to open later, but the proposed design will overcomplicate things.
I added support to load a shapefile from memory. This way if you store the shp/dbf files using go-bindata then you can load it using byte arrays.