Ejemplo n.º 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}'.");
            }
        }
Ejemplo n.º 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}'.");
            }
        }
Ejemplo n.º 3
0
        static void Convert(string inputPath, string outputPath)
        {
            Console.WriteLine($"Converting '{inputPath}' to '{outputPath}'...");
            Stopwatch w = Stopwatch.StartNew();

            using (Disposal disposal = new Disposal())
                using (JsonReader reader = BuildReader(inputPath, disposal))
                    using (JsonWriter writer = BuildWriter(outputPath, disposal))
                    {
                        writer.WriteToken(reader);
                    }

            Console.WriteLine($"Done in {w.Elapsed.TotalSeconds:n1}s; {ToSizeString(new FileInfo(inputPath).Length)} => {ToSizeString(new FileInfo(outputPath).Length)}");
        }
Ejemplo n.º 4
0
        static void Parse(string inputPath)
        {
            Console.WriteLine($"Timing Parse for '{inputPath}'...");
            Stopwatch w = Stopwatch.StartNew();

            using (Disposal disposal = new Disposal())
                using (JsonReader reader = BuildReader(inputPath, disposal))
                {
                    while (reader.Read())
                    {
                    }
                }

            Console.WriteLine($"Done in {w.Elapsed.TotalSeconds:n1}s; {ToSizeString(new FileInfo(inputPath).Length)}");
        }
Ejemplo n.º 5
0
        static SarifLog LoadSarif(string inputPath)
        {
            Console.WriteLine($"Timing load SARIF of '{inputPath}'...");
            long      memoryBefore = GC.GetTotalMemory(true);
            Stopwatch w            = Stopwatch.StartNew();

            SarifLog log = null;

            JsonSerializer serializer = new JsonSerializer();

            using (Disposal disposal = new Disposal())
                using (JsonReader reader = BuildReader(inputPath, disposal))
                {
                    log = serializer.Deserialize <SarifLog>(reader);
                }

            w.Stop();
            long memoryAfter = GC.GetTotalMemory(true);

            Console.WriteLine($"Done in {w.Elapsed.TotalSeconds:n1}s; {ToSizeString(new FileInfo(inputPath).Length)} on disk; {ToSizeString((memoryAfter - memoryBefore))} in memory.");
            return(log);
        }