Also support hash tiles

This commit is contained in:
2026-01-11 08:01:35 +01:00
parent 1633ad52c9
commit 84e3bbf442
2 changed files with 37 additions and 3 deletions

View File

@@ -43,7 +43,18 @@ func Decompress(data []byte) ([]byte, error) {
}
// DumpAllEntries reads and dumps all entries from tile data.
// Automatically detects if the tile is a data tile or hash tile.
func DumpAllEntries(tileData []byte) error {
// Try to read as data tile first
if err := dumpDataTile(tileData); err != nil {
// If it fails, try as hash tile
fmt.Fprintf(os.Stderr, "Not a data tile, trying as hash tile...\n")
return dumpHashTile(tileData)
}
return nil
}
func dumpDataTile(tileData []byte) error {
entryNum := 0
for len(tileData) > 0 {
e, remaining, err := sunlight.ReadTileLeaf(tileData)
@@ -61,6 +72,24 @@ func DumpAllEntries(tileData []byte) error {
return nil
}
func dumpHashTile(tileData []byte) error {
const hashSize = 32 // SHA-256 hash size
if len(tileData)%hashSize != 0 {
return fmt.Errorf("invalid hash tile: size %d is not a multiple of %d", len(tileData), hashSize)
}
numHashes := len(tileData) / hashSize
fmt.Printf("Hash tile with %d hashes:\n\n", numHashes)
for i := 0; i < numHashes; i++ {
hash := tileData[i*hashSize : (i+1)*hashSize]
fmt.Printf("Hash %d: %x\n", i, hash)
}
return nil
}
// DumpEntryAtPosition reads and dumps a specific entry at the given position.
func DumpEntryAtPosition(tileData []byte, position int, expectedIndex int64) error {
entryNum := 0