Skip to content

Instantly share code, notes, and snippets.

@takekazuomi
Created March 17, 2019 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takekazuomi/dbea826b1683c5868241a9c32c49f089 to your computer and use it in GitHub Desktop.
Save takekazuomi/dbea826b1683c5868241a9c32c49f089 to your computer and use it in GitHub Desktop.
IMultiStreamSource for gzipped file
public sealed class GzFileSource : IMultiStreamSource
{
private readonly string[] _paths;
public GzFileSource(params string[] paths)
{
if (paths == null || (paths.Length == 1 && paths[0] == null))
{
_paths = new string[0];
return;
}
_paths = paths;
}
public int Count
{
get { return _paths.Length; }
}
public string GetPathOrNull(int index)
{
return _paths[index];
}
public Stream Open(int index)
{
var path = _paths[index];
var s = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
return new GZipStream(s, CompressionMode.Decompress, false);
}
public TextReader OpenTextReader(int index)
{
return new StreamReader(Open(index));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment