예제 #1
0
        private byte[] Decode(byte[] code, HuffmanTreeBase tree, long streamSize)
        {
            MemoryStream             outputMemoryStream = new MemoryStream();
            FileDecodingInputStream  inputStream        = CreateFileDecodingInputStream(code);
            FileDecodingOutputStream outputStream       = CreateFileDecodingOutputStream(outputMemoryStream);

            try {
                new HuffmanDecoder().Decode(inputStream, tree, outputStream, streamSize, CancellationToken.None, null);
                return(outputMemoryStream.ToArray());
            }
            finally {
                inputStream.Dispose();
                outputStream.Dispose();
            }
        }
        private void Decode(string inputFile, string outputFolder, CancellationToken cancellationToken, IProgress <CodingProgressInfo> progress)
        {
            FileDecodingInputStream inputStream = new FileDecodingInputStream(inputFile, platform);

            ITaskProgressController tpc = CreateTaskProgressController(progress, inputStream);

            try {
                if (inputStream.IsEmpty)
                {
                    return;
                }

                StreamKind code = inputStream.ReadStreamFormat();
                if (code != StreamKind.WT_CODE)
                {
                    throw new StreamFormatException();
                }

                tpc.Start();
                directoriesQueue.Enqueue(currentDirectory = outputFolder);
                BootstrapSegment bootstrapSegment = streamParser.ParseWeightsTable(inputStream);
                while (!inputStream.IsEmpty)
                {
                    switch (inputStream.ReadStreamFormat())
                    {
                    case StreamKind.FS_CODE:
                        DecodeFile(inputStream, bootstrapSegment, cancellationToken, tpc);
                        break;

                    case StreamKind.DS_CODE:
                        DecodeDirectory(inputStream);
                        break;

                    default:
                        throw new StreamFormatException();
                    }
                }
                tpc.Finish();
            }
            catch {
                tpc.Error();
                throw;
            }
            finally {
                inputStream.Dispose();
            }
        }