Пример #1
0
 /// <summary>
 /// Creates an instance of the preferred <see cref="IBitStream"/> implementation for byte arrays.
 /// </summary>
 public static IBitStream Create(byte[] data)
 {
                 #if DEBUG
     var bs1 = new BitArrayStream(data);
     var bs2 = new ManagedBitStream();
     bs2.Initialize(new MemoryStream(data));
     var bs3 = new UnsafeBitStream();
     bs3.Initialize(new MemoryStream(data));
     return(new DebugBitStream(bs1, new DebugBitStream(bs2, bs3)));
                 #else
     var bs = new UnsafeBitStream();
     bs.Initialize(new MemoryStream(data));
     return(bs);
                 #endif
 }
Пример #2
0
        /// <summary>
        /// Creates an instance of the preferred <see cref="IBitStream"/> implementation for streams.
        /// </summary>
        public static IBitStream Create(Stream stream)
        {
                        #if DEBUG
            byte[] data;
            using (var memstream = new MemoryStream(checked ((int)stream.Length))) {
                stream.CopyTo(memstream);
                data = memstream.GetBuffer();
            }

            var bs1 = new BitArrayStream(data);
            var bs2 = new ManagedBitStream();
            bs2.Initialize(new MemoryStream(data));
            var bs3 = new UnsafeBitStream();
            bs3.Initialize(new MemoryStream(data));
            return(new DebugBitStream(bs1, new DebugBitStream(bs2, bs3)));
                        #else
            var bs = new UnsafeBitStream();
            bs.Initialize(stream);
            return(bs);
                        #endif
        }