From 19b02a3c4b589dbae1ff51d71a9032a46a3495df Mon Sep 17 00:00:00 2001 From: Symmetricity <184246+Symmetricity@users.noreply.github.com> Date: Wed, 13 May 2026 17:24:17 +0200 Subject: [PATCH] Write PMTiles archives in binary mode PMTiles files contain compressed binary tile and directory payloads. On Windows, opening the output stream in text mode can translate newline bytes as they are written. That changes the number of bytes written to disk without changing the offsets and lengths recorded in the PMTiles header. Open the PMTiles stream in binary mode and write compressed strings with write(). This preserves the existing format on POSIX while keeping Windows output byte counts aligned with the header. --- src/pmtiles.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pmtiles.cpp b/src/pmtiles.cpp index 5727c7f4..8cafa4be 100644 --- a/src/pmtiles.cpp +++ b/src/pmtiles.cpp @@ -15,7 +15,7 @@ PMTiles::~PMTiles() { } void PMTiles::open(std::string &filename) { std::cout << "Creating pmtiles at " << filename << std::endl; - outputStream.open(filename); + outputStream.open(filename, std::ios::out | std::ios::trunc | std::ios::binary); // dummy header/root directory for now - we'll write it all later char header[HEADER_ROOT] = "PMTiles"; outputStream.write(header, HEADER_ROOT); @@ -122,7 +122,7 @@ void PMTiles::flushEntries(std::vector &rootEntries, std::vect std::lock_guard lock(fileMutex); uint64_t location = outputStream.tellp(); uint64_t length = compressed.size(); - outputStream << compressed; + outputStream.write(compressed.c_str(), compressed.size()); // append reference to the root directory pmtiles::entryv3 rootEntry = pmtiles::entryv3(startId, location-leafStart, length, 0); @@ -150,7 +150,7 @@ void PMTiles::saveTile(int zoom, int x, int y, std::string &data) { std::lock_guard lock(fileMutex); // write to file offset = TileOffset(static_cast(outputStream.tellp()) - HEADER_ROOT, compressed.size()); - outputStream << compressed; + outputStream.write(compressed.c_str(), compressed.size()); numTilesWritten++; isNew = true; }