Skip to content

Commit

Permalink
WIP on write
Browse files Browse the repository at this point in the history
  • Loading branch information
bdon committed Sep 15, 2024
1 parent 9452367 commit 1f3b51f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
45 changes: 45 additions & 0 deletions pmtiles/write.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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.
}

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
}


// 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
29 changes: 29 additions & 0 deletions pmtiles/write_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package pmtiles

import (
// "log"
"os"
"io"
"io/ioutil"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)

func TestWriteHeader(t *testing.T) {
// logger := log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lshortfile)

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)

assert.Nil(t, nil)

// var input map[string]interface{}
// json.Unmarshal(b.Bytes(), &input)
// assert.Equal(t, "tippecanoe v2.5.0", input["generator"])
}

0 comments on commit 1f3b51f

Please sign in to comment.