public void ReadableStreamTest4()
        {
            using (var expected = new MemoryStream())
            {
                for (var i = 0; i < 10000; i++)
                {
                    expected.WriteByte((byte)(i % byte.MaxValue));
                }

                expected.Position = 0;
                using (var stream = SerializableBytes.CreateReadableStream(expected, CancellationToken.None))
                {
                    Assert.Equal(expected.Length, stream.Length);

                    var random = new Random(Environment.TickCount);
                    for (var i = 0; i < 100; i++)
                    {
                        var position = random.Next((int)expected.Length);
                        expected.Position = position;
                        stream.Position   = position;

                        Assert.Equal(expected.ReadByte(), stream.ReadByte());
                    }
                }
            }
        }
        public void ReadableStreamTest3()
        {
            using (var expected = new MemoryStream())
            {
                for (var i = 0; i < 10000; i++)
                {
                    expected.WriteByte((byte)(i % byte.MaxValue));
                }

                expected.Position = 0;
                using (var stream = SerializableBytes.CreateReadableStream(expected, CancellationToken.None))
                {
                    Assert.Equal(expected.Length, stream.Length);

                    stream.Position = 0;

                    int index = 0;
                    int count;
                    var bytes = new byte[1000];

                    while ((count = stream.Read(bytes, 0, bytes.Length)) > 0)
                    {
                        for (var i = 0; i < count; i++)
                        {
                            Assert.Equal((byte)(index % byte.MaxValue), bytes[i]);
                            index++;
                        }
                    }

                    Assert.Equal(index, stream.Length);
                }
            }
        }
Пример #3
0
        private Stream ReadStream(int projectId, int documentId, int nameId, object unused1, object unused2, CancellationToken cancellationToken)
        {
            using (var accessor = _esentStorage.GetDocumentTableAccessor())
                using (var esentStream = accessor.GetReadStream(projectId, documentId, nameId))
                {
                    if (esentStream == null)
                    {
                        return(null);
                    }

                    // this will copy over esent stream and let it go.
                    return(SerializableBytes.CreateReadableStream(esentStream, cancellationToken));
                }
        }
Пример #4
0
        private Stream ReadStream(EsentStorage.Key key, int nameId, object unused1, object unused2, CancellationToken cancellationToken)
        {
            using (var accessor = GetAccessor(key))
                using (var esentStream = accessor.GetReadStream(key, nameId))
                {
                    if (esentStream == null)
                    {
                        return(null);
                    }

                    // this will copy over esent stream and let it go.
                    return(SerializableBytes.CreateReadableStream(esentStream, cancellationToken));
                }
        }
Пример #5
0
        private Stream ReadBlobIntoPooledStream(SafeSqliteBlobHandle blob, int length)
        {
            var bytes = SQLitePersistentStorage.GetPooledBytes();

            try
            {
                ThrowIfNotOk(NativeMethods.sqlite3_blob_read(blob, bytes, length, offset: 0));

                // Copy those bytes into a pooled stream
                return(SerializableBytes.CreateReadableStream(bytes, length));
            }
            finally
            {
                // Return our small array back to the pool.
                SQLitePersistentStorage.ReturnPooledBytes(bytes);
            }
        }
        public void ReadableStreamTest2()
        {
            using (var expected = new MemoryStream())
            {
                for (var i = 0; i < 10000; i++)
                {
                    expected.WriteByte((byte)(i % byte.MaxValue));
                }

                expected.Position = 0;
                using (var stream = SerializableBytes.CreateReadableStream(expected, 1000, CancellationToken.None))
                {
                    Assert.Equal(1000, stream.Length);

                    expected.Position = 0;
                    stream.Position   = 0;
                    for (var i = 0; i < 1000; i++)
                    {
                        Assert.Equal(expected.ReadByte(), stream.ReadByte());
                    }
                }
            }
        }
Пример #7
0
 protected override Stream GetSourceStream(CancellationToken cancellationToken)
 => SerializableBytes.CreateReadableStream(_xmlDocCommentBytes);