Skip to content

Commit

Permalink
Compress the data files
Browse files Browse the repository at this point in the history
Completes #36
  • Loading branch information
mattjohnsonpint committed Jun 14, 2019
1 parent 5cc2dd4 commit 98f6e8f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/GeoTimeZone.DataBuilder/TimeZoneDataBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using NetTopologySuite.Geometries;

Expand All @@ -12,16 +13,17 @@ public static class TimeZoneDataBuilder
private static readonly Dictionary<string, TimeZoneMeta> TimeZones = new Dictionary<string, TimeZoneMeta>();


private const string DataFileName = "TZ.dat";
private const string LookupFileName = "TZL.dat";
private const string DataFileName = "TZ.dat.gz";
private const string LookupFileName = "TZL.dat.gz";

private static void WriteLookup(string outputPath)
{

var path = Path.Combine(outputPath, LookupFileName);

using (var fileStream = File.Create(path))
using (var writer = new StreamWriter(fileStream))
using (var compressedStream = new GZipStream(fileStream, CompressionMode.Compress))
using (var writer = new StreamWriter(compressedStream))
{
writer.NewLine = "\n";
var timeZones = TimeZones.Values.OrderBy(x => x.LineNumber);
Expand All @@ -37,7 +39,8 @@ private static void WriteGeohashDataFile(string outputPath)
var path = Path.Combine(outputPath, DataFileName);

using (var fileStream = File.Create(path))
using (var writer = new StreamWriter(fileStream))
using (var compressedStream = new GZipStream(fileStream, CompressionMode.Compress))
using (var writer = new StreamWriter(compressedStream))
{
writer.NewLine = "\n";
WriteTreeNode(writer, WorldBoundsTreeNode);
Expand Down
2 changes: 1 addition & 1 deletion src/GeoTimeZone/GeoTimeZone.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</PropertyGroup>

<ItemGroup>
<EmbeddedResource Include="TZ.dat;TZL.dat" />
<EmbeddedResource Include="TZ.dat.gz;TZL.dat.gz" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.1' ">
Expand Down
4 changes: 3 additions & 1 deletion src/GeoTimeZone/TimeZoneLookup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;

#if NETSTANDARD1_1
Expand Down Expand Up @@ -132,7 +133,8 @@ private static IList<string> LoadLookupData()
var assembly = typeof(TimeZoneLookup).Assembly;
#endif

using (var stream = assembly.GetManifestResourceStream("GeoTimeZone.TZL.dat"))
using (var compressedStream = assembly.GetManifestResourceStream("GeoTimeZone.TZL.dat.gz"))
using (var stream = new GZipStream(compressedStream, CompressionMode.Decompress))
{
if (stream == null)
throw new InvalidOperationException();
Expand Down
4 changes: 3 additions & 1 deletion src/GeoTimeZone/TimezoneFileReader.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.IO.Compression;
using System.Text;

#if NETSTANDARD1_1
Expand Down Expand Up @@ -27,7 +28,8 @@ private static MemoryStream LoadData()
var assembly = typeof(TimezoneFileReader).Assembly;
#endif

using (var stream = assembly.GetManifestResourceStream("GeoTimeZone.TZ.dat"))
using (var compressedStream = assembly.GetManifestResourceStream("GeoTimeZone.TZ.dat.gz"))
using (var stream = new GZipStream(compressedStream, CompressionMode.Decompress))
{
if (stream == null)
throw new InvalidOperationException();
Expand Down

0 comments on commit 98f6e8f

Please sign in to comment.