コード例 #1
0
        public void TestImmediateDecompression()
        {
            byte[]        compressedByteArray = Zstd.Compress(this._saoRaw);
            Memory <byte> compressedMemory    = Zstd.Compress(this._saoRaw.AsMemory());

            Assert.AreEqual(compressedByteArray.Length, compressedMemory.Length, "compressed byte[] length does not match compressed Memory<byte> length");

            byte[] compressedMemoryArray = compressedMemory.ToArray();
            Assert.IsTrue(compressedMemoryArray.SequenceEqual(compressedByteArray), "compressed byte[] content does not match compressed Memory<byte> content");


            // ------- DECOMPRESSION ------- \\
            byte[]        decompressedByteArray = Zstd.Decompress(compressedByteArray, this._saoRaw.Length);
            Memory <byte> decompressedMemory    = Zstd.Decompress(compressedMemory, this._saoRaw.Length);

            Assert.AreEqual(decompressedByteArray.Length, decompressedMemory.Length, "decompressed byte[] length does not match decompressed Memory<byte> length");

            byte[] decompressedMemoryArray = decompressedMemory.ToArray();
            Assert.IsTrue(decompressedMemoryArray.SequenceEqual(decompressedByteArray), "decompressed byte[] content does not match decompressed Memory<byte> content");

            Assert.IsTrue(decompressedByteArray.SequenceEqual(this._saoRaw), "decompressed byte[] does not match raw data content");
            Assert.IsTrue(decompressedMemoryArray.SequenceEqual(this._saoRaw), "decompressed Memory<byte> does not match raw data content");

            Assert.Pass();
        }
コード例 #2
0
        public void Write(Stream stream)
        {
            byte[] magic         = Encoding.ASCII.GetBytes("RMAN");
            byte   major         = 2;
            byte   minor         = 0;
            byte   unknown       = 0;
            byte   signatureType = 0;
            int    contentOffset = 4 + 4 + 4 + 4 + 8 + 4;

            byte[] uncompressedFile        = new byte[FlatBufferSerializer.Default.GetMaxSize(this._body)];
            int    uncompressedContentSize = FlatBufferSerializer.Default.Serialize(this._body, uncompressedFile);

            Array.Resize(ref uncompressedFile, uncompressedContentSize);

            byte[] compressedFile        = Zstd.Compress(uncompressedFile);
            int    compressedContentSize = compressedFile.Length;

            using (BinaryWriter bw = new BinaryWriter(stream))
            {
                bw.Write(magic);
                bw.Write(major);
                bw.Write(minor);
                bw.Write(unknown);
                bw.Write(signatureType);
                bw.Write(contentOffset);
                bw.Write(compressedContentSize);
                bw.Write(this.ID);
                bw.Write(uncompressedContentSize);
                bw.Write(compressedFile);
            }
        }
コード例 #3
0
        public void TestImmediateCompression()
        {
            byte[]        compressedByteArray = Zstd.Compress(this._saoRaw);
            Memory <byte> compressedMemory    = Zstd.Compress(this._saoRaw.AsMemory());

            Assert.AreEqual(compressedByteArray.Length, compressedMemory.Length, "compressed byte[] length does not match compressed Memory<byte> length");

            byte[] compressedMemoryArray = compressedMemory.ToArray();
            Assert.IsTrue(compressedMemoryArray.SequenceEqual(compressedByteArray), "compressed byte[] content does not match compressed Memory<byte> content");

            Assert.Pass();
        }