Skip to content

Commit f3b725f

Browse files
Copilotbertt
andcommitted
Make VectorTileEncoder.Encode return the stream for fluent API usage
Co-authored-by: bertt <538812+bertt@users.noreply.github.com>
1 parent c67c4ab commit f3b725f

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ layer.VectorTileFeatures.Add(feature);
4848

4949
// Encode to stream
5050
var layers = new List<VectorTileLayer> { layer };
51-
var outputStream = new MemoryStream();
52-
VectorTileEncoder.Encode(layers, outputStream);
51+
var stream = VectorTileEncoder.Encode(layers, new MemoryStream());
5352

5453
// Save to file
55-
File.WriteAllBytes("output.pbf", outputStream.ToArray());
54+
File.WriteAllBytes("output.pbf", ((MemoryStream)stream).ToArray());
5655
```
5756

5857
Tip: If you use this library with vector tiles loading from a webserver, you could run into the following exception:

src/VectorTileEncoder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Mapbox.Vector.Tile;
66

77
public static class VectorTileEncoder
88
{
9-
public static void Encode(List<VectorTileLayer> layers, Stream stream)
9+
public static Stream Encode(List<VectorTileLayer> layers, Stream stream)
1010
{
1111
var tile = new Tile();
1212

@@ -48,5 +48,6 @@ public static void Encode(List<VectorTileLayer> layers, Stream stream)
4848
}
4949

5050
Serializer.Serialize(stream, tile);
51+
return stream;
5152
}
5253
}

0 commit comments

Comments
 (0)