Esempio n. 1
0
        /**
         * <inheritdoc/>
         */
        public Tag <List <ITag> > CreateFromData(byte[] value)
        {
            int         length = value.Length;
            ICompressor compressor;

            byte[] bitData;
            using (BigBinaryReader bbr = new BigBinaryReader(new MemoryStream(value)))
            {
                short compressorLength = bbr.ReadInt16();

                length -= 2 + compressorLength;

                byte[] compressorBytes = new byte[compressorLength];
                bbr.Read(compressorBytes, 0, compressorLength);
                string compressionName = Encoding.UTF8.GetString(compressorBytes);
                compressor = ODSUtil.GetCompressor(compressionName);
                if (compressor == null)
                {
                    throw new ODSException("Cannot find compressor: " + compressionName);
                }
                bitData = bbr.ReadBytes((int)(bbr.BaseStream.Length - bbr.BaseStream.Position));
            }

            this.compressor = compressor;

            byte[] decompressedData;
            using (MemoryStream memStream = new MemoryStream())
            {
                using (Stream compressedStream = compressor.GetDecompressStream(new MemoryStream(bitData)))
                {
                    compressedStream.CopyTo(memStream);
                }
                decompressedData = memStream.ToArray();
            }

            this.value = InternalUtils.GetListData <ITag>(decompressedData);
            return(this);
        }