コード例 #1
0
        public void ExtractFileInMem()
        {
            void Template(string fileName)
            { // Type 1
                EngineState s         = EngineTests.CreateEngineState();
                string      srcScript = Path.Combine("%TestBench%", "EncodedFile", "ExtractFileTests.script");

                srcScript = StringEscaper.Preprocess(s, srcScript);
                Script sc = s.Project.LoadScriptRuntime(srcScript, new LoadScriptRuntimeOptions());

                byte[] extractDigest;
                using (MemoryStream ms = EncodedFile.ExtractFileInMem(sc, "FolderExample", fileName))
                {
                    ms.Position   = 0;
                    extractDigest = HashHelper.GetHash(HashHelper.HashType.SHA256, ms);
                }

                string originFile = Path.Combine("%TestBench%", "EncodedFile", fileName);

                originFile = StringEscaper.Preprocess(s, originFile);
                byte[] originDigest;
                using (FileStream fs = new FileStream(originFile, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    originDigest = HashHelper.GetHash(HashHelper.HashType.SHA256, fs);
                }

                // Compare Hash
                Assert.IsTrue(originDigest.SequenceEqual(extractDigest));
            }

            Template("Type1.jpg"); // Type 1
            Template("Type2.7z");  // Type 2
            Template("Type3.pdf"); // Type 3
        }