public void TestDeserialize()
        {
            long length = long.MaxValue;
            MultiStreamHeaderItem item = new MultiStreamHeaderItem();

            byte[] buffer = BitConverter.GetBytes(length);

            item.Deserialize(buffer);

            Assert.AreEqual(length, item.Length);
        }
        public void TestSerialize()
        {
            long length = long.MaxValue;
            MultiStreamHeaderItem item = new MultiStreamHeaderItem
            {
                Length = length
            };

            byte[] buffer = item.Serialize();

            Assert.AreEqual(length, BitConverter.ToInt64(buffer, 0));
        }
        public void TestCanDeserializeSerializedItem()
        {
            long length = long.MaxValue;
            MultiStreamHeaderItem item = new MultiStreamHeaderItem
            {
                Length = length
            };

            byte[] buffer = item.Serialize();
            MultiStreamHeaderItem newItem = new MultiStreamHeaderItem();

            newItem.Deserialize(buffer);

            Assert.AreEqual(length, newItem.Length);
        }
Exemple #4
0
        public void Write(string outputFilePath, OutputQueue outputQueue, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(outputFilePath))
            {
                throw new ArgumentException("Output file path must be non-empty");
            }
            if (outputQueue == null)
            {
                throw new ArgumentNullException("Output queue must be non-empty");
            }

            GZipMultiStreamHeader multiStreamHeader = new GZipMultiStreamHeader();

            for (int i = 0; i < outputQueue.Count; i++)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    break;
                }

                OutputWorkItem        workItem = outputQueue[i];
                MultiStreamHeaderItem multiStreamHeaderItem = new MultiStreamHeaderItem
                {
                    Length = workItem.OutputStream.Stream.Length
                };

                multiStreamHeader.Items.Add(multiStreamHeaderItem);
            }

            OutputWorkItem firstOutputWorkItem = outputQueue[0];
            IBlockReader   blockReader         = new BlockReader();

            firstOutputWorkItem.OutputStream.Stream.Position = 0;

            Block block = blockReader.Read(firstOutputWorkItem.OutputStream.Stream, BlockFlags.All);

            if (cancellationToken.IsCancellationRequested)
            {
                return;
            }

            block.ExtraField = multiStreamHeader.Serialize();
            multiStreamHeader.Items[0].Length = block.Length;
            block.ExtraField = multiStreamHeader.Serialize();
            block.Flags     |= GZipFlags.FEXTRA;

            IGZipBlockWriter blockWriter = new BlockWriter();

            using (FileStream outputFileStream = File.Create(outputFilePath))
            {
                blockWriter.Write(outputFileStream, block, BlockFlags.All);

                for (int i = 1; i < outputQueue.Count; i++)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }

                    OutputWorkItem workItem = outputQueue[i];

                    using (Stream compressedStream = workItem.OutputStream.Stream)
                    {
                        compressedStream.Position = 0;
                        compressedStream.CopyTo(outputFileStream);
                    }
                }
            }
        }