Beispiel #1
0
        public MemoryStream DecompressEntry(int Index)
        {
            MemoryStream    result = new MemoryStream();
            FileEntryStruct e      = Files[Index];
            uint            count  = 0;

            byte[]     inputBlock;
            byte[]     outputBlock = new byte[Header.MaxBlockSize];
            long       left        = e.RealUncompressedSize;
            FileStream fs          = new FileStream(MyFileName, FileMode.Open, FileAccess.Read);

            fs.Seek(e.BlockOffsets[0], SeekOrigin.Begin);
            byte[] buff;
            if (e.BlockSizeIndex == 0xFFFFFFFF)
            {
                buff = new byte[e.RealUncompressedSize];
                fs.Read(buff, 0, buff.Length);
                result.Write(buff, 0, buff.Length);
            }
            else
            {
                while (left > 0)
                {
                    uint compressedBlockSize = (uint)e.BlockSizes[count];
                    if (compressedBlockSize == 0)
                    {
                        compressedBlockSize = Header.MaxBlockSize;
                    }
                    if (compressedBlockSize == Header.MaxBlockSize || compressedBlockSize == left)
                    {
                        buff = new byte[compressedBlockSize];
                        fs.Read(buff, 0, buff.Length);
                        result.Write(buff, 0, buff.Length);
                        left -= compressedBlockSize;
                    }
                    else
                    {
                        var uncompressedBlockSize = (uint)Math.Min(left, Header.MaxBlockSize);
                        if (compressedBlockSize < 5)
                        {
                            throw new Exception("compressed block size smaller than 5");
                        }
                        inputBlock = new byte[compressedBlockSize];
                        fs.Read(inputBlock, 0, (int)compressedBlockSize);
                        uint actualUncompressedBlockSize = uncompressedBlockSize;
                        uint actualCompressedBlockSize   = compressedBlockSize;
                        outputBlock = SevenZipHelper.Decompress(inputBlock, (int)actualUncompressedBlockSize);
                        if (outputBlock.Length != actualUncompressedBlockSize)
                        {
                            throw new Exception("Decompression Error");
                        }
                        result.Write(outputBlock, 0, (int)actualUncompressedBlockSize);
                        left -= uncompressedBlockSize;
                    }
                    count++;
                }
            }
            fs.Close();
            return(result);
        }
Beispiel #2
0
        internal void ReadReplayData()
        {
            if (rawReplayCompressed == null)
            {
                return;
            }

            if (replay == null)
            {
                replay = new List <bReplayFrame>();
            }
            else
            {
                replay.Clear();
            }

            try
            {
                ReadReplayData(new ASCIIEncoding().GetString(SevenZipHelper.Decompress(rawReplayCompressed)));
            }
            catch (Exception)
            {
                replay.Clear();
            }

#if DEBUG
            StreamWriter w = File.CreateText("replay.txt");
            foreach (bReplayFrame f in replay)
            {
                w.WriteLine("{0} {1} {2} {3} {4} {5} {6}", f.time, f.mouseX, f.mouseY, f.mouseLeft1, f.mouseLeft2, f.mouseRight1, f.mouseRight2);
            }
            w.Close();
#endif
        }
Beispiel #3
0
 public static void SaveFile(string filePath, ReplayFile replay)
 {
     using (ReplayWriter beatmapWriter = new ReplayWriter(File.Open(filePath, FileMode.Create)))
     {
         beatmapWriter.Write(replay.Mode);
         beatmapWriter.Write(replay.Version);
         beatmapWriter.Write(replay.BeatmapHash);
         beatmapWriter.Write(replay.PlayerName);
         beatmapWriter.Write(replay.ReplayHash);
         beatmapWriter.Write(replay.Count300);
         beatmapWriter.Write(replay.Count100);
         beatmapWriter.Write(replay.Count50);
         beatmapWriter.Write(replay.CountGeki);
         beatmapWriter.Write(replay.CountKatu);
         beatmapWriter.Write(replay.CountMiss);
         beatmapWriter.Write(replay.Score);
         beatmapWriter.Write(replay.MaxCombo);
         beatmapWriter.Write(replay.FullCombo);
         beatmapWriter.Write(replay.UsedMods);
         beatmapWriter.Write(replay.PerformanceGraphData);
         beatmapWriter.Write(replay.ReplayDate);
         string[] list = Encoding.ASCII.GetString(SevenZipHelper.Decompress(replay.Replay)).Split(',');
         beatmapWriter.Write(replay.Replay);
         beatmapWriter.Write(replay.Long0);
     }
 }
        private void ReadReplay(bool replayDecompress)
        {
            CompressedReplayData = ReadByteArray();

            if (replayDecompress)
            {
                ReplayFrames           = new List <ReplayFrame>();
                DecompressedReplayData = SevenZipHelper.Decompress(CompressedReplayData);

                string replayData = Encoding.ASCII.GetString(DecompressedReplayData);
                if (replayData.Length > 0)
                {
                    string[] replayLines = replayData.Split(',');

                    ReplayFrame lastFrame;
                    if (ReplayFrames.Count > 0)
                    {
                        lastFrame = ReplayFrames[ReplayFrames.Count - 1];
                    }
                    else
                    {
                        lastFrame = new ReplayFrame(0, 0, 0);
                    }

                    foreach (string replayLine in replayLines)
                    {
                        if (replayLine.Length == 0)
                        {
                            continue;
                        }

                        string[] data = replayLine.Split('|');
                        if (data.Length < 4)
                        {
                            continue;
                        }

                        if (data[0] == "-12345")
                        {
                            Seed = int.Parse(data[3]);
                            continue;
                        }

                        ReplayFrame nextFrame = new ReplayFrame(
                            int.Parse(data[0]) + lastFrame.Time,
                            float.Parse(data[1], _nfi),
                            float.Parse(data[2], _nfi)
                            );

                        ReplayFrames.Add(nextFrame);
                        lastFrame = nextFrame;
                    }
                }
            }

            if (Version >= 20140721)
            {
                OnlineId = _reader.ReadInt64();
            }
        }
Beispiel #5
0
        public TextAsset(AssetPreloadData preloadData, bool readSwitch)
        {
            AssetsFile   sourceFile = preloadData.sourceFile;
            EndianStream stream     = preloadData.sourceFile.a_Stream;

            stream.Position       = preloadData.Offset;
            preloadData.extension = ".txt";
            if (sourceFile.platform == -2)
            {
                uint num2 = stream.ReadUInt32();
                PPtr ptr  = sourceFile.ReadPPtr();
                PPtr ptr2 = sourceFile.ReadPPtr();
            }
            this.m_Name = stream.ReadAlignedString(stream.ReadInt32());
            if (this.m_Name != "")
            {
                preloadData.Name = this.m_Name;
            }
            else
            {
                preloadData.Name = preloadData.TypeString + " #" + preloadData.uniqueID;
            }
            int count = stream.ReadInt32();

            if (readSwitch)
            {
                this.m_Script = new byte[count];
                stream.Read(this.m_Script, 0, count);
                if (this.m_Script[0] == 0x5d)
                {
                    this.m_Script = SevenZipHelper.Decompress(this.m_Script);
                }
                if ((this.m_Script[0] == 60) || ((((this.m_Script[0] == 0xef) && (this.m_Script[1] == 0xbb)) && (this.m_Script[2] == 0xbf)) && (this.m_Script[3] == 60)))
                {
                    preloadData.extension = ".xml";
                }
            }
            else
            {
                if (stream.ReadByte() == 0x5d)
                {
                    stream.Position       += 4L;
                    preloadData.exportSize = stream.ReadInt32();
                    stream.Position       -= 8L;
                }
                else
                {
                    preloadData.exportSize = count;
                }
                stream.Position += count - 1;
            }
            stream.AlignStream(4);
            this.m_PathName = stream.ReadAlignedString(stream.ReadInt32());
        }
Beispiel #6
0
        override public byte[] Expand(byte[] inputbuffer, int realsize)
        {
            var ret = SevenZipHelper.Decompress(inputbuffer);

            if (ret.Length != realsize)
            {
                System.Console.WriteLine("WARNING! I expected this lzma block to be " + realsize + " byte long, but it is in fact " + ret.Length + " bytes long");
                if (ret.Length == inputbuffer.Length)
                {
                    System.Console.WriteLine("I have the feeling decompression did NOT take place somehow(?)");
                }
            }
            return(ret);
        }
Beispiel #7
0
    static Assembly ReadAssemblyFromResource(AssemblyName assemblyName)
    {
        var resStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(assemblyName.Name.ToLower());

        if (resStream == null)
        {
            return(null);
        }

        var assemblyStream = new BinaryReader(resStream);

        byte[] data = SevenZipHelper.Decompress(assemblyStream.ReadBytes((int)assemblyStream.BaseStream.Length));
        return(Assembly.Load(data));
    }
Beispiel #8
0
        public static byte[] Decompress(byte[] data, InfoByte.CompressionType comprUsed)
        {
            byte[] dcd = new byte[0];
            try
            {
                switch (comprUsed)
                {
                case InfoByte.CompressionType.Arithmetic:
                    AbstractModel ac = new ModelOrder0();
                    using (MemoryStream msd = new MemoryStream())
                    {
                        using (MemoryStream min = new MemoryStream(data))
                        {
                            min.Flush();
                            min.Position = 0;
                            ac.Process(min, msd, ModeE.MODE_DECODE);
                            msd.Flush();
                            dcd = msd.ToArray();
                        }
                    }
                    break;

                case InfoByte.CompressionType.BZIP2:
                    using (MemoryStream msOut = new MemoryStream(data))
                    {
                        byte[] blen = new byte[4];
                        msOut.Read(blen, 0, 4);
                        int len = BitConverter.ToInt32(blen, 0);
                        using (BZip2InputStream d = new BZip2InputStream(msOut))
                        {
                            dcd = new byte[len];
                            d.Read(dcd, 0, dcd.Length);
                        }
                    }
                    break;

                case InfoByte.CompressionType.LZMA:
                    return(SevenZipHelper.Decompress(data));

                case InfoByte.CompressionType.None:
                    return(data);
                }
            }
            catch {}
            return(dcd);
        }
Beispiel #9
0
        public static byte[] Decompress(byte[] data, string type)
        {
            switch (type)
            {
            case CompressionAlgorithm.Zlib:
                return(ZlibStream.UncompressBuffer(data));

            case CompressionAlgorithm.Deflate:
                return(DeflateStream.UncompressBuffer(data));

            case CompressionAlgorithm.GZip:
                return(GZipStream.UncompressBuffer(data));

            case CompressionAlgorithm.Lzma:
                return(SevenZipHelper.Decompress(data));
            }

            return(data);
        }
Beispiel #10
0
        public void Do()
        {
            try
            {
                if (_compressOrDecompress)
                {
                    _output = SevenZipHelper.Compress(_input);
                }
                else
                {
                    _output = SevenZipHelper.Decompress(_input);
                }
            }
            catch (Exception e)
            {
                _exceptionMessage = e.Message;
            }

            _over = true;
        }
        public static byte[] DeCompress(byte[] bytesToDecompress, CompressionType compressionProvider)
        {
            if (compressionProvider == CompressionType.SevenZip)
            {
                return(SevenZipHelper.Decompress(bytesToDecompress));
            }

            var writeData = new byte[4096];

            Stream s2 = InputStream(new MemoryStream(bytesToDecompress), compressionProvider);

            var outStream = new MemoryStream();

            while (true)

            {
                int size = s2.Read(writeData, 0, writeData.Length);

                if (size > 0)

                {
                    outStream.Write(writeData, 0, size);
                }

                else

                {
                    break;
                }
            }

            s2.Close();

            byte[] outArr = outStream.ToArray();

            outStream.Close();

            return(outArr);
        }
Beispiel #12
0
        private static void ExtractAllResources()
        {
            using (var reader = new ResourceReader(_xllFile))
            {
                Console.WriteLine("OK");
                Console.WriteLine();

                if (reader.RecordCount > 0 && !Directory.Exists(_outFolder))
                {
                    Directory.CreateDirectory(_outFolder);
                }

                IResourceRecord resource;
                while ((resource = reader.Read()) != null)
                {
                    var outputFileName = GetFileNameWithExtension(resource);
                    Console.Write("Extracting {0} ({1}) . . . ", Path.GetFileName(outputFileName), resource.Type);

                    var outputFilePath = Path.Combine(_outFolder, outputFileName);

                    if (File.Exists(outputFilePath) && !_overwrite)
                    {
                        Console.WriteLine("Error");
                        throw new ApplicationException(string.Format("The file {0} already exists and --overwrite was not specified", outputFileName));
                    }

                    using (var stream = new FileStream(outputFilePath, FileMode.Create))
                    {
                        var binaryData = resource.IsLzmaCompressed()
                            ? SevenZipHelper.Decompress(resource.BinaryData)
                            : resource.BinaryData;
                        stream.Write(binaryData, 0, binaryData.Length);
                    }

                    Console.WriteLine("OK");
                }
            }
        }
Beispiel #13
0
        static ReplayFile flipNotes(ReplayFile replay)
        {
            Console.Clear();
            Console.WriteLine("Flipping notes (HR was toggled)...");
            string[] list = Encoding.ASCII.GetString(SevenZipHelper.Decompress(replay.Replay)).Split(',');
            for (int index = 0; index < list.Length; index++)
            {
                int percentage = (int)((double)index / list.Length * 100);
                Console.SetCursorPosition(0, 1);
                Console.WriteLine(percentage.ToString().PadLeft(3) + "% done.");

                string[] strArray = list[index].Split('|');
                if (strArray.Length == 4)
                {
                    double num = 384.0 - double.Parse(strArray[2], new CultureInfo("en-US"));
                    strArray[2] = num.ToString(new CultureInfo("en-US"));
                    list[index] = string.Join("|", strArray);
                }
            }

            Console.WriteLine("Compressing replay data...");
            replay.Replay = SevenZipHelper.Compress(Encoding.ASCII.GetBytes(string.Join(",", list)));
            return(replay);
        }
 /// <summary>
 /// Decodes the encrypted data
 /// </summary>
 /// <param name="inputStream">The encrypted data stream</param>
 /// <param name="outputStream">The output stream</param>
 /// <returns>The decrypted data</returns>
 public void Decode(Stream inputStream, Stream outputStream)
 {
     SevenZipHelper.Decompress(inputStream, outputStream, DecompressedSize);
 }
        public async Task DecompressEntryAsync(int index, Stream output)
        {
            var entry = Files[index];

            using (var fs = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.None, 4096, useAsync: true))
            {
                fs.Seek(entry.BlockOffsets[0], SeekOrigin.Begin);

                //not compressed
                if (entry.BlockSizeIndex == 0xFFFFFFFF)
                {
                    var uncompressed = new byte[entry.RealUncompressedSize];
                    await fs.ReadAsync(uncompressed, 0, uncompressed.Length).ConfigureAwait(continueOnCapturedContext: false);

                    await output.WriteAsync(uncompressed, 0, uncompressed.Length).ConfigureAwait(continueOnCapturedContext: false);

                    return;
                }

                var decompressor = new TransformBlock <InputBlock, byte[]>(
                    input => input.IsCompressed
                        ? SevenZipHelper.Decompress(input.Data, input.UncompressedSize)
                        : input.Data
                    , new ExecutionDataflowBlockOptions {
                    MaxDegreeOfParallelism = DataflowBlockOptions.Unbounded
                }
                    );

                var outputWriter = new ActionBlock <byte[]>(
                    data => output.Write(data, 0, data.Length)
                    );

                decompressor.LinkTo(outputWriter, new DataflowLinkOptions {
                    PropagateCompletion = true
                });

                uint count = 0;
                long left  = entry.RealUncompressedSize;
                while (left > 0)
                {
                    uint compressedBlockSize = entry.BlockSizes[count];
                    if (compressedBlockSize == 0)
                    {
                        compressedBlockSize = Header.MaxBlockSize;
                    }

                    if (compressedBlockSize == Header.MaxBlockSize ||
                        compressedBlockSize == left)
                    {
                        left -= compressedBlockSize;
                        var uncompressedData = new byte[compressedBlockSize];
                        await fs.ReadAsync(uncompressedData, 0, uncompressedData.Length).ConfigureAwait(continueOnCapturedContext: false);

                        decompressor.Post(new InputBlock(uncompressedData, InputBlock.Uncompressed));
                    }
                    else
                    {
                        var uncompressedBlockSize = Math.Min(left, Header.MaxBlockSize);
                        left -= uncompressedBlockSize;
                        if (compressedBlockSize < 5)
                        {
                            throw new Exception("compressed block size smaller than 5");
                        }

                        var compressedData = new byte[compressedBlockSize];
                        await fs.ReadAsync(compressedData, 0, (int)compressedBlockSize).ConfigureAwait(continueOnCapturedContext: false);

                        decompressor.Post(new InputBlock(compressedData, uncompressedBlockSize));
                    }
                    count++;
                }

                decompressor.Complete();
                await outputWriter.Completion;
            }
        }
Beispiel #16
0
        public void DecompressEntry(sfarFile entry, Stream input, Stream output)
        {
#endif
            int count = 0;

            byte[] inputBlock;
            byte[] outputBlock = new byte[MaximumBlockSize];

            var left = entry.uncompressedSize;

            input.Seek(entry.dataOffset[0], SeekOrigin.Begin);

            if (entry.blockSizeIndex == -1)
            {
                output.WriteFromStream(input, entry.uncompressedSize);
            }
            else
            {
                while (left > 0)
                {
                    uint compressedBlockSize = (uint)entry.blockSizeArray[count];
                    if (compressedBlockSize == 0)
                    {
                        compressedBlockSize = MaximumBlockSize;
                    }

                    if (CompressionScheme == CompressionScheme.None)
                    {
                        output.WriteFromStream(input, compressedBlockSize);
                        left -= compressedBlockSize;
                    }
                    else if (CompressionScheme == CompressionScheme.Lzma)
                    {
                        if (compressedBlockSize == MaximumBlockSize ||
                            compressedBlockSize == left)
                        {
                            output.WriteFromStream(input, compressedBlockSize);
                            left -= compressedBlockSize;
                        }
                        else
                        {
                            var uncompressedBlockSize = (uint)Math.Min(left, MaximumBlockSize);

                            if (compressedBlockSize < 5)
                            {
                                throw new InvalidOperationException();
                            }

                            inputBlock = new byte[compressedBlockSize];

                            //var properties = input.ReadBytes(5);
                            //compressedBlockSize -= 5;

                            if (input.Read(inputBlock, 0, (int)compressedBlockSize)
                                != compressedBlockSize)
                            {
                                throw new EndOfStreamException();
                            }

                            uint actualUncompressedBlockSize = uncompressedBlockSize;
                            uint actualCompressedBlockSize   = compressedBlockSize;

                            /*var error = LZMA.Decompress(
                             *  outputBlock,
                             *  ref actualUncompressedBlockSize,
                             *  inputBlock,
                             *  ref actualCompressedBlockSize,
                             *  properties,
                             *  (uint)properties.Length);
                             *
                             * if (error != LZMA.ErrorCode.Ok ||
                             *  uncompressedBlockSize != actualUncompressedBlockSize ||
                             *  compressedBlockSize != actualCompressedBlockSize)
                             * {
                             *  throw new InvalidOperationException();
                             * }*/

                            outputBlock = SevenZipHelper.Decompress(inputBlock, (int)actualUncompressedBlockSize);
                            if (outputBlock.Length != actualUncompressedBlockSize)
                            {
                                throw new NotImplementedException();
                            }

                            output.Write(outputBlock, 0, (int)actualUncompressedBlockSize);
                            left -= uncompressedBlockSize;

#if (WITH_GUI)
                            if (BWork != null)
                            {
                                int perc = (int)(((float)count / (float)(entry.blockSizeArray.Length)) * 100);
                                if (perc > maxPerc)
                                {
                                    maxPerc = perc;
                                    BWork.ReportProgress(perc);
                                }
                            }
#endif
                        }
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                    count++;
                }
            }
        }// end of DecompressEntry
Beispiel #17
0
        private void UdpListenerWorkMethod()
        {
            List <Socket> udpListenerSockets = SocketHelper.GetUdpMulticastSocketForReceiver(MulticastGroupIpEndPoint);

            try
            {
                byte[]   dataBuffer = null;
                EndPoint remoteEP   = null;

                while (true)
                {
                    Socket udpListenerSocket = null;
                    while (true)
                    {
                        bool dataAvailable = false;
                        for (int i = 0; i < udpListenerSockets.Count; i++)
                        {
                            udpListenerSocket = udpListenerSockets[i];

                            if (udpListenerSocket != null && udpListenerSocket.Available > 0)
                            {
                                dataAvailable = true;
                                break;
                            }
                        }
                        if (dataAvailable == true)
                        {
                            break;
                        }
                        //Wait
                        Thread.Sleep(100);
                    }

                    remoteEP   = new IPEndPoint(IPAddress.Any, 0);
                    dataBuffer = new byte[udpListenerSocket.Available];
                    int dataLength = udpListenerSocket.ReceiveFrom(dataBuffer, ref remoteEP);

                    dataBuffer = SevenZipHelper.Decompress(dataBuffer);

                    int     msgHeaderDataLength;
                    Message message = GetMessageFromBytes(dataBuffer, out msgHeaderDataLength);

                    if (message == null || message.HeaderData == null || msgHeaderDataLength < 0)
                    {
                        continue;
                    }

                    IPAddress ipAddress = IPAddress.None;

                    if (remoteEP is IPEndPoint)
                    {
                        ipAddress = (remoteEP as IPEndPoint).Address;
                    }

                    if (message.HeaderData.MsgDataType != EMsgDataType.ReceiveConfirmation)
                    {
                        SendReceiveConfirmationMessage(message.HeaderData.RefNo, ipAddress);
                    }

                    ProcessMessage(message, ipAddress);

                    dataBuffer = null;
                    remoteEP   = null;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            for (int i = 0; i < udpListenerSockets.Count; i++)
            {
                if (udpListenerSockets[i] != null)
                {
                    udpListenerSockets[i].Close();
                }
            }
        }
Beispiel #18
0
        internal TextAsset([NotNull] AssetPreloadData preloadData, bool metadataOnly)
        {
            var sourceFile = preloadData.Source;
            var reader     = sourceFile.FileReader;

            reader.Position = preloadData.Offset;

            if (sourceFile.Platform == AssetPlatform.UnityPackage)
            {
                var objectHideFlags    = reader.ReadUInt32();
                var prefabParentObject = sourceFile.ReadPPtr();
                var prefabInternal     = sourceFile.ReadPPtr();
            }

            Name = reader.ReadAlignedString();

            var scriptSize = reader.ReadInt32();

            if (metadataOnly)
            {
                var isLzmaCompressed = reader.ReadByte();

                if (isLzmaCompressed == 93)
                {
                    reader.Position += 4;
                    preloadData.Size = reader.ReadInt32(); //actualy int64
                    Size             = preloadData.Size;
                    reader.Position -= 8;
                }
                else
                {
                    preloadData.Size = scriptSize;
                }

                reader.Position += scriptSize - 1;
            }
            else
            {
                var script = new byte[scriptSize];

                reader.Read(script, 0, scriptSize);

                if (script[0] == 93)
                {
                    script = SevenZipHelper.Decompress(script);
                }

                RawData = script;

                Size = scriptSize;
            }

            var assetDataVersionNumbers = preloadData.Source.VersionComponents;

            // It seems like the "PathName" property was removed in 2017.4.
            if (assetDataVersionNumbers[0] < 2017 ||
                (assetDataVersionNumbers[0] == 2017 && assetDataVersionNumbers[1] <= 3))
            {
                reader.AlignBy(4);

                PathName = reader.ReadAlignedString();
            }
            else
            {
                PathName = Name;
            }
        }
        public MemoryStream DecompressEntry(int index, FileStream fs)
        {
            var  result = new MemoryStream();
            var  e      = DlcFiles[index];
            uint count  = 0;
            var  left   = e.RealUncompressedSize;

            fs.Seek(e.BlockOffsets[0], SeekOrigin.Begin);
            byte[] buff;

            if (e.BlockSizeIndex == 0xFFFFFFFF)
            {
                buff = new byte[e.RealUncompressedSize];
                fs.Read(buff, 0, buff.Length);
                result.Write(buff, 0, buff.Length);
            }
            else
            {
                while (left > 0)
                {
                    uint compressedBlockSize = e.BlockSizes[count];

                    if (compressedBlockSize == 0)
                    {
                        compressedBlockSize = _header.MaxBlockSize;
                    }

                    if (compressedBlockSize == _header.MaxBlockSize || compressedBlockSize == left)
                    {
                        buff = new byte[compressedBlockSize];
                        fs.Read(buff, 0, buff.Length);
                        result.Write(buff, 0, buff.Length);
                        left -= compressedBlockSize;
                    }
                    else
                    {
                        var uncompressedBlockSize = (uint)Math.Min(left, _header.MaxBlockSize);

                        if (compressedBlockSize < 5)
                        {
                            throw new Exception("compressed block size smaller than 5");
                        }

                        var inputBlock = new byte[compressedBlockSize];
                        fs.Read(inputBlock, 0, (int)compressedBlockSize);
                        var actualUncompressedBlockSize = uncompressedBlockSize;
                        //var actualCompressedBlockSize = compressedBlockSize;
                        var outputBlock = SevenZipHelper.Decompress(inputBlock, (int)actualUncompressedBlockSize);

                        if (outputBlock.Length != actualUncompressedBlockSize)
                        {
                            throw new Exception("Decompression Error");
                        }

                        result.Write(outputBlock, 0, (int)actualUncompressedBlockSize);
                        left -= uncompressedBlockSize;
                    }

                    count++;
                }
            }

            return(result);
        }
Beispiel #20
0
        //when dealing with byte streams (what we call Raw in the GUI) it's always
        //good to have a byte buffer around. we'll use it when copying the data.
        //readonly byte[] FBuffer = new byte[1024];

        private void DecompressAsync(object io)
        {
            CompressorIO IO = (CompressorIO)io;

            IO.OutBytes = SevenZipHelper.Decompress(IO.InBytes);
        }