コード例 #1
0
        public void PartialStream()
        {
            byte[] bytes = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            using (MemoryStream memoryStream = new MemoryStream())
            {
                memoryStream.Write(bytes, 0, bytes.Length);

                Stream partialStream1 = StreamUtility.CreatePartialStream(memoryStream, 3, 4, Ownership.None);
                CollectionAssert.AreEqual(new byte[] { 3, 4, 5, 6 }, partialStream1.ReadAllBytes());

                Stream partialStream2 = StreamUtility.CreatePartialStream(memoryStream, 6, null, Ownership.None);
                CollectionAssert.AreEqual(new byte[] { 6, 7, 8, 9, 10 }, partialStream2.ReadAllBytes());
            }
        }
コード例 #2
0
        public void PartialStreamCopyTo()
        {
            byte[] bytes = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            using (MemoryStream memoryStream = new MemoryStream())
            {
                memoryStream.Write(bytes, 0, bytes.Length);

                Stream partialStream1 = StreamUtility.CreatePartialStream(memoryStream, 3, 4, Ownership.None);
                using (var destination = new MemoryStream())
                {
                    partialStream1.CopyTo(destination);
                    CollectionAssert.AreEqual(new byte[] { 3, 4, 5, 6 }, destination.ToArray());
                }

                Stream partialStream2 = StreamUtility.CreatePartialStream(memoryStream, 6, null, Ownership.None);
                using (var destination = new MemoryStream())
                {
                    partialStream2.CopyTo(destination);
                    CollectionAssert.AreEqual(new byte[] { 6, 7, 8, 9, 10 }, destination.ToArray());
                }
            }
        }