-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Print a JSON representation of part of the header [#63] * refactor show to take io.Writer instead of os.Stdout * add integration test for Show command * hide write command as it's not implemented yet.
- Loading branch information
Showing
11 changed files
with
211 additions
and
24 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
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
dist/ | ||
go-pmtiles | ||
*.pmtiles | ||
/*.pmtiles | ||
/*.mbtiles | ||
*.json | ||
*.geojson | ||
*.tsv.gz |
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
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package pmtiles | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"github.com/stretchr/testify/assert" | ||
"log" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestShowHeader(t *testing.T) { | ||
var b bytes.Buffer | ||
logger := log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lshortfile) | ||
err := Show(logger, &b, "", "fixtures/test_fixture_1.pmtiles", true, false, false, "", false, 0, 0, 0) | ||
assert.Nil(t, err) | ||
|
||
var input map[string]interface{} | ||
json.Unmarshal(b.Bytes(), &input) | ||
assert.Equal(t, "mvt", input["TileType"]) | ||
assert.Equal(t, "gzip", input["TileCompression"]) | ||
} | ||
|
||
func TestShowMetadata(t *testing.T) { | ||
var b bytes.Buffer | ||
logger := log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lshortfile) | ||
err := Show(logger, &b, "", "fixtures/test_fixture_1.pmtiles", false, true, false, "", false, 0, 0, 0) | ||
assert.Nil(t, err) | ||
|
||
var input map[string]interface{} | ||
json.Unmarshal(b.Bytes(), &input) | ||
assert.Equal(t, "tippecanoe v2.5.0", input["generator"]) | ||
} |
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,42 @@ | ||
package pmtiles | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
) | ||
|
||
func Write(logger *log.Logger, inputArchive string, newHeaderJsonFile string, newMetadataFile string) error { | ||
if newMetadataFile == "" { | ||
if newHeaderJsonFile == "" { | ||
return fmt.Errorf("No data to write.") | ||
} | ||
// we can write the header in-place without writing the whole file. | ||
return nil | ||
} | ||
|
||
// write metadata: | ||
// always writes in this order: | ||
// copy the header | ||
// copy the root directory | ||
// write the new the metadata | ||
// copy the leaf directories | ||
// copy the tile data | ||
file, err := os.OpenFile(inputArchive, os.O_RDWR, 0666) | ||
|
||
buf := make([]byte, 127) | ||
_, err = file.Read(buf) | ||
if err != nil { | ||
return err | ||
} | ||
originalHeader, _ := deserializeHeader(buf) | ||
|
||
// modify the header | ||
|
||
buf = serializeHeader(originalHeader) | ||
_, err = file.WriteAt(buf, 0) | ||
if err != nil { | ||
return err | ||
} | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package pmtiles | ||
|
||
import ( | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func TestWriteHeader(t *testing.T) { | ||
tempDir, _ := ioutil.TempDir("", "testing") | ||
defer os.RemoveAll(tempDir) | ||
src, _ := os.Open("fixtures/test_fixture_1.pmtiles") | ||
defer src.Close() | ||
dest, _ := os.Create(filepath.Join(tempDir, "test.pmtiles")) | ||
defer dest.Close() | ||
_, _ = io.Copy(dest, src) | ||
} |