コード例 #1
0
 public static void SetPosition()
 {
     using var ms      = new MemoryStream(new byte[] { 1, 3, 5, 8, 12 });
     using var segment = new StreamSegment(ms);
     segment.Adjust(1, 3);
     segment.Position = 1;
     Equal(5, segment.ReadByte());
     Equal(2, segment.Position);
     segment.Position = 0;
     Equal(3, segment.ReadByte());
     Equal(1, segment.Position);
 }
コード例 #2
0
        public static void ReadApm()
        {
            using var ms      = new MemoryStream(new byte[] { 1, 3, 5, 8, 12 });
            using var segment = new StreamSegment(ms);
            segment.Adjust(1L, 2L);
            var buffer = new byte[4];
            var ar     = segment.BeginRead(buffer, 0, 2, null, null);

            Equal(2, segment.EndRead(ar));
            Equal(3, buffer[0]);
            Equal(5, buffer[1]);
            Equal(0, buffer[2]);
        }
コード例 #3
0
        public static async Task ReadRangeAsync()
        {
            using var ms      = new MemoryStream(new byte[] { 1, 3, 5, 8, 12 });
            using var segment = new StreamSegment(ms);
            segment.Adjust(1L, 2L);
            var buffer = new byte[4];

            Equal(2, await segment.ReadAsync(buffer, 0, buffer.Length));
            Equal(3, buffer[0]);
            Equal(5, buffer[1]);
            Equal(0, buffer[2]);
            Equal(0, buffer[3]);
            //read from the end of the stream
            Equal(-1, segment.ReadByte());
        }
コード例 #4
0
        public static void ReadByteSequentially()
        {
            using var ms      = new MemoryStream(new byte[] { 1, 3, 5, 8, 12 });
            using var segment = new StreamSegment(ms);
            Equal(0, segment.Position);
            segment.Adjust(0, 2);
            Equal(1, segment.ReadByte());
            Equal(1, segment.Position);

            Equal(3, segment.ReadByte());
            Equal(2, segment.Position);

            Equal(-1, segment.ReadByte());
            Equal(2, segment.Position);
        }
コード例 #5
0
        public static void ReadRange()
        {
            var ms = new MemoryStream(new byte[] { 1, 3, 5, 8, 12 });

            using (var segment = new StreamSegment(ms))
            {
                segment.Adjust(1L, 2L);
                var buffer = new byte[4];
                Equal(2, segment.Read(buffer, 0, buffer.Length));
                Equal(3, buffer[0]);
                Equal(5, buffer[1]);
                Equal(0, buffer[2]);
                Equal(0, buffer[3]);
                //read from the end of the stream
                Equal(-1, segment.ReadByte());
            }
        }