private static void CompareUncompressed(string jsonFilePath)
        {
            string bionFilePath = Path.ChangeExtension(jsonFilePath, ".bion");
            string comparePath  = Path.ChangeExtension(jsonFilePath, "compare.json");

            JsonBionConverter.JsonToBion(jsonFilePath, bionFilePath);
            JsonBionConverter.BionToJson(bionFilePath, comparePath);
            Verify.JsonEqual(jsonFilePath, comparePath);
        }
示例#2
0
        private static void ToBion(string jsonPath, string bionPath, string dictionaryPath)
        {
            VerifyFileExists(jsonPath);

            using (new ConsoleWatch($"Converting {jsonPath} to {bionPath}...",
                                    () => $"Done. {FileLength.MB(jsonPath)} JSON to {FileLength.MB(bionPath)} BION{(String.IsNullOrEmpty(dictionaryPath) ? "" : $" + {FileLength.MB(dictionaryPath)} dictionary")} ({FileLength.Percentage(jsonPath, bionPath, dictionaryPath)})"))
            {
                JsonBionConverter.JsonToBion(jsonPath, bionPath, dictionaryPath);
            }
        }
示例#3
0
        private static void Index(string jsonRootPath, string bionRootPath)
        {
            using (new ConsoleWatch($"Converting under \"{jsonRootPath}\" to \"{bionRootPath}\"..."))
            {
                jsonRootPath = Path.GetFullPath(jsonRootPath);

                foreach (string jsonFilePath in Directory.EnumerateFiles(jsonRootPath, "*.*", SearchOption.AllDirectories))
                {
                    string jsonFilePathUnderRoot = jsonFilePath.Substring(jsonRootPath.Length + 1);
                    string outputPath            = Path.ChangeExtension(Path.Combine(bionRootPath, jsonFilePathUnderRoot), ".bion");
                    if (!File.Exists(outputPath))
                    {
                        System.Console.WriteLine($"  {jsonFilePathUnderRoot}");
                        Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
                        JsonBionConverter.JsonToBion(jsonFilePath, outputPath, Path.ChangeExtension(outputPath, ".wdx"));
                    }
                }
            }
        }
示例#4
0
        public void ContainerIndex_EndToEnd()
        {
            string jsonFilePath   = @"Content\Medium.json";
            string bionFilePath   = Path.ChangeExtension(jsonFilePath, ".bion");
            string dictionaryPath = Path.ChangeExtension(bionFilePath, "dict.bion");
            string comparePath    = Path.ChangeExtension(jsonFilePath, "compare.json");

            JsonBionConverter.JsonToBion(jsonFilePath, bionFilePath, dictionaryPath);

            using (WordCompressor compressor = WordCompressor.OpenRead(dictionaryPath))
                using (ContainerIndex cIndex = ContainerIndex.OpenRead(Path.ChangeExtension(bionFilePath, ".cdx")))
                    using (BionReader reader = new BionReader(File.OpenRead(bionFilePath), cIndex, compressor))
                    {
                        for (int i = 0; i < cIndex.Count; ++i)
                        {
                            ContainerEntry container = cIndex[i];

                            // Seek to container start
                            reader.Seek(container.StartByteOffset);

                            // Verify a container start is there
                            int depth = reader.Depth;
                            reader.Read();

                            bool isObject = (reader.TokenType == BionToken.StartObject);
                            Assert.AreEqual((isObject ? BionToken.StartObject : BionToken.StartArray), reader.TokenType);

                            // Read until the depth is back to the same value
                            while (reader.Depth != depth)
                            {
                                reader.Read();
                            }

                            // Verify this is the end container position
                            Assert.AreEqual((isObject ? BionToken.EndObject : BionToken.EndArray), reader.TokenType);
                            Assert.AreEqual(container.EndByteOffset, reader.BytesRead);
                        }
                    }
        }