Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Two10.CountryLookup/ReverseLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,26 @@ static IEnumerable<Region> ParseInput(IEnumerable<string> geojson)

static IEnumerable<string> LoadFile()
{
// The whole file is not being deserialized to not waste memory unnecessarily.
// Deserializing each line separately should consume less resources.
var assembly = Assembly.GetExecutingAssembly();
using (var stream = assembly.GetManifestResourceStream(assembly.GetManifestResourceNames().First()))
using (var reader = new StreamReader(stream))
{
string line = null;
while ((line = reader.ReadLine()) != null)
{
// Skip root json object (first and last lines)
if (line.Length < 100)
continue;

// Remove trailing commas that make file geojson compatible
if (line[line.Length - 1] == ',')
line = line.Remove(line.Length - 1, 1);

yield return line;
}
}
}


}
}
2 changes: 1 addition & 1 deletion Two10.CountryLookup/Two10.CountryLookup.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<Compile Include="GeoJsonParser.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="region-list.json" />
<EmbeddedResource Include="region-list.geojson" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
Loading