Ejemplo n.º 1
0
    private static byte[] Compress(byte[] data)
    {
        var buffer    = new DecompressedBuffer(data);
        var container = new CompressedContainer(buffer);

        return(container.SerializeData());
    }
Ejemplo n.º 2
0
    private static byte[] Decompress(byte[] data)
    {
        var container = new CompressedContainer(data);
        var buffer    = new DecompressedBuffer(container);

        return(buffer.Data);
    }
        public void CompressedDataSameAsMicrosoftImplementation()
        {
            var buffer    = new DecompressedBuffer(_validDecompressedDirStream);
            var container = new CompressedContainer(buffer);

            Assert.True(container.SerializeData().SequenceEqual(_validCompressedDirStream));
        }
Ejemplo n.º 4
0
        public VbaStorage(CFStorage VBAStorage)
        {
            // DIR STREAM -------------------------
            CFStream thisWorkbookStream = VBAStorage.GetStream("dir");

            Byte[] compressedData = thisWorkbookStream.GetData();

            var reader    = new XlBinaryReader(ref compressedData);
            var container = new CompressedContainer(reader);

            // Decompress
            var buffer = new DecompressedBuffer();

            container.Decompress(buffer);
            Byte[] uncompressed = buffer.GetData();

            var uncompressedDataReader = new XlBinaryReader(ref uncompressed);

            this.DirStream = new DirStream(uncompressedDataReader);

            // MODULE STREAMS ----------------------------------------
            this.ModuleStreams = new Dictionary <string, ModuleStream>(DirStream.ModulesRecord.Modules.Length);
            foreach (var module in DirStream.ModulesRecord.Modules)
            {
                var streamName  = module.StreamNameRecord.GetStreamNameAsString();
                var stream      = VBAStorage.GetStream(streamName).GetData();
                var localreader = new XlBinaryReader(ref stream);

                var moduleStream = new ModuleStream(DirStream.InformationRecord, module, localreader);

                this.ModuleStreams.Add(streamName, moduleStream);
            }
        }
        public void CompressDecompressDataAreEqual()
        {
            var buffer    = new DecompressedBuffer(_validDecompressedDirStream);
            var container = new CompressedContainer(buffer);
            var newBuffer = new DecompressedBuffer(container);

            Assert.True(newBuffer.Data.SequenceEqual(_validDecompressedDirStream));
        }
        private static IEnumerable <IToken> GetTokensFromCompressedContainer(CompressedContainer refCompressed)
        {
            var refTokens = from c in refCompressed.CompressedChunks
                            from s in ((CompressedChunkData)c.ChunkData).TokenSequences
                            from t in s.Tokens
                            select t;

            return(refTokens);
        }
Ejemplo n.º 7
0
        public void GivenLargeByteSequenceWithLowCompressibilityCompressionProducesContainerWithMultipleRawChunks()
        {
            var data = GetLargeByteSequenceWithLowCompressibility().ToArray();

            var container = new CompressedContainer(new DecompressedBuffer(data));

            Assert.True(container.CompressedChunks.Count() > 1);
            Assert.True(container.CompressedChunks.Count(c => c.Header.IsCompressed) <= 1);  // last chunk may be compressed
        }
        public void GivenCompressedDataThatSerializingItReproducesSameData()
        {
            var refCompressed = new CompressedContainer(_validCompressedDirStream);

            var actual = refCompressed.SerializeData();

            Assert.Equal(_validCompressedDirStream.Length, actual.Length);
            Assert.Equal(_validCompressedDirStream, actual);
        }
Ejemplo n.º 9
0
        public ModuleStream(PROJECTINFORMATION ProjectInformation, MODULE module, XlBinaryReader Data)
        {
            this.ProjectInformation = ProjectInformation;

            this.PerformanceCache = Data.ReadBytes(module.OffsetRecord.TextOffset);

            Byte[] rest      = Data.GetUnreadData();
            var    reader    = new XlBinaryReader(ref rest);
            var    container = new CompressedContainer(reader);
            var    buffer    = new DecompressedBuffer();

            container.Decompress(buffer);
            this.UncompressedSourceCode = buffer.GetData();
        }
        public static void LowLevelCompressionComparison(byte[] decompressedBytes, byte[] expectedCompressedBytes)
        {
            var refCompressed = new CompressedContainer(expectedCompressedBytes);
            var decompressed  = new DecompressedBuffer(decompressedBytes);
            var sutCompressed = new CompressedContainer(decompressed);

            var refTokens = GetTokensFromCompressedContainer(refCompressed).OfType <CopyToken>().ToList();
            var sutTokens = GetTokensFromCompressedContainer(sutCompressed).OfType <CopyToken>().ToList();

            //Assert.Equal(refTokens.Count, sutTokens.Count);
            for (var i = 0; i < refTokens.Count; i++)
            {
                var expected = refTokens[i];
                var actual   = sutTokens[i];
                Assert.Equal(expected, actual);
            }
        }
Ejemplo n.º 11
0
        public void DecompressionTest()
        {
            Byte[] CompressedData = TestData.CompressedData;
            var    reader         = new XlBinaryReader(ref CompressedData);

            reader.OutputAllAsBinary();

            var container = new CompressedContainer(reader);
            var buffer    = new DecompressedBuffer();

            container.Decompress(buffer);
            Byte[] uncompressed = buffer.GetData();

            bool success = Enumerable.SequenceEqual(uncompressed, TestData.UncompressedData);

            Assert.IsTrue(success, "Uncompressed byte sequence not equal to expected byte sequence");
        }
        public void ParsedCompressedDataIsSameAsInput()
        {
            var container = new CompressedContainer(_validCompressedDirStream);

            Assert.True(container.SerializeData().SequenceEqual(_validCompressedDirStream));
        }
        public void CanCreateCompressedContainer()
        {
            var container = new CompressedContainer(_validCompressedDirStream);

            Assert.IsType <CompressedContainer>(container);
        }