Example #1
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);
            }
        }
Example #2
0
        private Stream ReadBlob(SafeSqliteBlobHandle blob)
        {
            var length = NativeMethods.sqlite3_blob_bytes(blob);

            // If it's a small blob, just read it into one of our pooled arrays, and then
            // create a PooledStream over it.
            if (length <= SQLitePersistentStorage.MaxPooledByteArrayLength)
            {
                return(ReadBlobIntoPooledStream(blob, length));
            }
            else
            {
                // Otherwise, it's a large stream.  Just take the hit of allocating.
                var bytes = new byte[length];
                ThrowIfNotOk(NativeMethods.sqlite3_blob_read(blob, bytes, length, offset: 0));
                return(new MemoryStream(bytes));
            }
        }