Exemple #1
0
        static JsonWriter BuildWriter(string filePath, Disposal disposal)
        {
            string extension = Path.GetExtension(filePath).ToLowerInvariant();

            Stream outStream = disposal.Add(File.Create(filePath));

            switch (extension)
            {
            case ".zip":
                outStream = disposal.Add(new DeflateStream(outStream, CompressionMode.Compress));
                extension = Path.GetExtension((filePath.Substring(0, filePath.Length - ".zip".Length))).ToLowerInvariant();
                break;

            case ".lz4":
                outStream = disposal.Add(LZ4Stream.Encode(outStream, LZ4Level.L09_HC));
                extension = Path.GetExtension((filePath.Substring(0, filePath.Length - ".lz4".Length))).ToLowerInvariant();
                break;
            }

            switch (extension)
            {
            case ".json":
            case ".sarif":
                return(disposal.Add(new JsonTextWriter(disposal.Add(new StreamWriter(outStream)))));

            case ".bson":
                return(disposal.Add(new BsonDataWriter(outStream)));

            case ".bion":
                return(disposal.Add(new BionDataWriter(outStream)));

            default:
                throw new NotImplementedException($"Don't know writer type for file extension '{extension}'.");
            }
        }
Exemple #2
0
        static JsonReader BuildReader(string filePath, Disposal disposal)
        {
            string extension = Path.GetExtension(filePath).ToLowerInvariant();

            Stream inStream = disposal.Add(File.OpenRead(filePath));

            switch (extension)
            {
            case ".zip":
                inStream  = disposal.Add(new DeflateStream(inStream, CompressionMode.Decompress));
                extension = Path.GetExtension((filePath.Substring(0, filePath.Length - ".zip".Length))).ToLowerInvariant();
                break;

            case ".lz4":
                inStream  = disposal.Add(LZ4Stream.Decode(inStream));
                extension = Path.GetExtension((filePath.Substring(0, filePath.Length - ".lz4".Length))).ToLowerInvariant();
                break;
            }

            switch (extension)
            {
            case ".json":
            case ".sarif":
                return(disposal.Add(new JsonTextReader(disposal.Add(new StreamReader(inStream)))));

            case ".bson":
                return(disposal.Add(new BsonDataReader(inStream)));

            case ".bion":
                return(disposal.Add(new BionDataReader(inStream)));

            default:
                throw new NotImplementedException($"Don't know reader type for file extension '{extension}'.");
            }
        }