示例#1
0
        // [InlineData("apache-license.html.blast")]
        public void decompress_test_files(string compressedSourceFile)
        {
            // setup
            var    baseFolder         = GetTestFileFolder();
            string expectedOutputFile = Path.GetFileNameWithoutExtension(compressedSourceFile);

            string compressedSourceFilePath = Path.Combine(baseFolder, compressedSourceFile);
            string expectedOutputFilePath   = Path.Combine(baseFolder, expectedOutputFile);
            string actualOutputFilePath     = Path.Combine(baseFolder, ".output", expectedOutputFile);

            Directory.CreateDirectory(Path.GetDirectoryName(actualOutputFilePath));

            using (var input = new FileStream(compressedSourceFilePath, FileMode.Open, FileAccess.Read))
                using (var output = new FileStream(actualOutputFilePath, FileMode.Create, FileAccess.Write))
                {
                    // test
                    var b = new Blast(input, output);
                    b.Decompress();

                    output.Flush();
                }

            // assert
            AssertFile(expectedOutputFilePath, actualOutputFilePath);
        }
示例#2
0
        public Stream GetContent(uint hash)
        {
            PackageEntry e;

            if (!index.TryGetValue(hash, out e))
            {
                return(null);
            }

            s.Seek(dataStart + e.Offset, SeekOrigin.Begin);
            var data = s.ReadBytes((int)e.Length);

            return(new MemoryStream(Blast.Decompress(data)));
        }
        public Stream GetStream(string filename)
        {
            Entry e;

            if (!index.TryGetValue(filename, out e))
            {
                return(null);
            }

            s.Seek(dataStart + e.Offset, SeekOrigin.Begin);
            var data = s.ReadBytes((int)e.Length);

            return(new MemoryStream(Blast.Decompress(data)));
        }
示例#4
0
            public Stream GetStream(string filename)
            {
                if (!index.TryGetValue(filename, out var e))
                {
                    return(null);
                }

                s.Seek(dataStart + e.Offset, SeekOrigin.Begin);

                var ret = new MemoryStream();

                Blast.Decompress(s, ret);
                ret.Seek(0, SeekOrigin.Begin);

                return(ret);
            }
示例#5
0
        public void basic_decompression_from_example()
        {
            // setup
            byte[] compressedInput = { 0x00, 0x04, 0x82, 0x24, 0x25, 0x8f, 0x80, 0x7f };
            byte[] expectedResult  = Encoding.ASCII.GetBytes("AIAIAIAIAIAIA");

            var actualOutput = new MemoryStream();

            // test
            var sut = new Blast(new MemoryStream(compressedInput, writable: false), actualOutput);

            sut.Decompress();

            byte[] actualResult = actualOutput.ToArray();

            // assert
            actualResult.ShouldBe(expectedResult);
        }
示例#6
0
        static void ExtractFromPackage(ExtractionType type, string path, MiniYaml actionYaml, List <string> extractedFiles, Action <string> updateMessage)
        {
            var sourcePath = Path.Combine(path, actionYaml.Value);

            // Try as an absolute path
            if (!File.Exists(sourcePath))
            {
                sourcePath = Platform.ResolvePath(actionYaml.Value);
            }

            using (var source = File.OpenRead(sourcePath))
            {
                foreach (var node in actionYaml.Nodes)
                {
                    var targetPath = Platform.ResolvePath(node.Key);

                    if (File.Exists(targetPath))
                    {
                        Log.Write("install", "Skipping installed file " + targetPath);
                        continue;
                    }

                    var offsetNode = node.Value.Nodes.FirstOrDefault(n => n.Key == "Offset");
                    if (offsetNode == null)
                    {
                        Log.Write("install", "Skipping entry with missing Offset definition " + targetPath);
                        continue;
                    }

                    var lengthNode = node.Value.Nodes.FirstOrDefault(n => n.Key == "Length");
                    if (lengthNode == null)
                    {
                        Log.Write("install", "Skipping entry with missing Length definition " + targetPath);
                        continue;
                    }

                    var length = FieldLoader.GetValue <int>("Length", lengthNode.Value.Value);
                    source.Position = FieldLoader.GetValue <int>("Offset", offsetNode.Value.Value);

                    extractedFiles.Add(targetPath);
                    Directory.CreateDirectory(Path.GetDirectoryName(targetPath));
                    var displayFilename = Path.GetFileName(Path.GetFileName(targetPath));

                    Action <long> onProgress = null;
                    if (length < ShowPercentageThreshold)
                    {
                        updateMessage("Extracting " + displayFilename);
                    }
                    else
                    {
                        onProgress = b => updateMessage("Extracting " + displayFilename + " ({0}%)".F(100 * b / length));
                    }

                    using (var target = File.OpenWrite(targetPath))
                    {
                        Log.Write("install", "Extracting {0} -> {1}".F(sourcePath, targetPath));
                        if (type == ExtractionType.Blast)
                        {
                            Action <long, long> onBlastProgress = (read, _) =>
                            {
                                if (onProgress != null)
                                {
                                    onProgress(read);
                                }
                            };

                            Blast.Decompress(source, target, onBlastProgress);
                        }
                        else
                        {
                            CopyStream(source, target, length, onProgress);
                        }
                    }
                }
            }
        }
        static void ExtractFromPackage(ExtractionType type, string path, MiniYaml actionYaml, List <string> extractedFiles, Action <string> updateMessage)
        {
            // Yaml path may be specified relative to a named directory (e.g. ^SupportDir) or the detected disc path
            var sourcePath = actionYaml.Value.StartsWith("^") ? Platform.ResolvePath(actionYaml.Value) : Path.Combine(path, actionYaml.Value);

            using (var source = File.OpenRead(sourcePath))
            {
                foreach (var node in actionYaml.Nodes)
                {
                    var targetPath = Platform.ResolvePath(node.Key);

                    if (File.Exists(targetPath))
                    {
                        Log.Write("install", "Skipping installed file " + targetPath);
                        continue;
                    }

                    var offsetNode = node.Value.Nodes.FirstOrDefault(n => n.Key == "Offset");
                    if (offsetNode == null)
                    {
                        Log.Write("install", "Skipping entry with missing Offset definition " + targetPath);
                        continue;
                    }

                    var lengthNode = node.Value.Nodes.FirstOrDefault(n => n.Key == "Length");
                    if (lengthNode == null)
                    {
                        Log.Write("install", "Skipping entry with missing Length definition " + targetPath);
                        continue;
                    }

                    var length = FieldLoader.GetValue <int>("Length", lengthNode.Value.Value);
                    source.Position = FieldLoader.GetValue <int>("Offset", offsetNode.Value.Value);

                    extractedFiles.Add(targetPath);
                    Directory.CreateDirectory(Path.GetDirectoryName(targetPath));
                    var displayFilename = Path.GetFileName(Path.GetFileName(targetPath));

                    Action <long> onProgress = null;
                    if (length < ShowPercentageThreshold)
                    {
                        updateMessage("Extracting " + displayFilename);
                    }
                    else
                    {
                        onProgress = b => updateMessage($"Extracting {displayFilename} ({100 * b / length}%)");
                    }

                    using (var target = File.OpenWrite(targetPath))
                    {
                        Log.Write("install", $"Extracting {sourcePath} -> {targetPath}");
                        if (type == ExtractionType.Blast)
                        {
                            Blast.Decompress(source, target, (read, _) => onProgress?.Invoke(read));
                        }
                        else
                        {
                            CopyStream(source, target, length, onProgress);
                        }
                    }
                }
            }
        }