-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,352 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,4 +35,4 @@ jobs: | |
- name: build | ||
run: go build ./... | ||
- name: test | ||
run: go test ./... | ||
run: go test ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package shapefile | ||
|
||
import ( | ||
"archive/zip" | ||
"fmt" | ||
"io" | ||
"strings" | ||
|
||
"golang.org/x/net/html/charset" | ||
) | ||
|
||
// CPG a CPG is a .cpg file. | ||
type CPG struct { | ||
Charset string | ||
} | ||
|
||
// ReadCPG reads a CPG from an io.Reader. | ||
func ReadCPG(r io.Reader, _ int64) (*CPG, error) { | ||
data, err := io.ReadAll(r) | ||
if err != nil { | ||
return nil, err | ||
} | ||
enc, name := charset.Lookup(strings.ToLower(string(data))) | ||
if enc == nil { | ||
return nil, fmt.Errorf("unknown charset '%s'", (string(data))) | ||
} | ||
return &CPG{ | ||
Charset: name, | ||
}, nil | ||
} | ||
|
||
// ReadCPGZipFile reads a CPG from a *zip.File. | ||
func ReadCPGZipFile(zipFile *zip.File) (*CPG, error) { | ||
readCloser, err := zipFile.Open() | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer readCloser.Close() | ||
cpg, err := ReadCPG(readCloser, int64(zipFile.UncompressedSize64)) | ||
if err != nil { | ||
return nil, fmt.Errorf("%s: %w", zipFile.Name, err) | ||
} | ||
return cpg, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.