Append-friendlier serial tiles serializer #206
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
The serialtiles serializer is written like a pretty reasonable newline delimited stream writer with the one exception that in the final
_flush
case it decides to not write a trailing newline. This causes all kinds of headaches for anyone attempting to resume or append to a previously written serialtiles files.What happens now (newlines visualized for ease). Note that the last line does not have a trailing
\n
.Now let's append to this stream assuming we can write in a way consistent with the previous writes...
Not great.
So then appenders do some trickery...
No big deal, appenders can just write lines with a prefixed newline!
\n{ ... }
Great! But what if our append starts after the initial header is written or while another initial stream is writing rather than after the first stream has concluded?
Oww, now we end up with an empty line (the empty string sandwiched between
\n\n
). 🍔Proposed solution
\n\n
for anyone who's been trying to append and has hit this corner case.This is a breaking change though some testing indicates previous versions of tilelive handle a single trailing
\n
on serialtiles files fine.For safety will bump major.
cc @rclark @mapbox/core-tech