Created
March 17, 2019 18:45
-
-
Save takekazuomi/dbea826b1683c5868241a9c32c49f089 to your computer and use it in GitHub Desktop.
IMultiStreamSource for gzipped file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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