/// <summary> /// Creates an instance of the preferred <see cref="IBitStream"/> implementation for streams. /// </summary> public static IBitStream Create(Stream stream) { #if BITSTREAMDEBUG 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 #if YOLO var bs = new UnsafeBitStream(); #else var bs = new ManagedBitStream(); #endif bs.Initialize(stream); return(bs); #endif }
/// <summary> /// Creates an instance of the preferred <see cref="IBitStream"/> implementation for byte arrays. /// </summary> public static IBitStream Create(byte[] data) { #if BITSTREAMDEBUG 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 #if YOLO var bs = new UnsafeBitStream(); #else var bs = new ManagedBitStream(); #endif bs.Initialize(new MemoryStream(data)); return(bs); #endif }