예제 #1
0
파일: DiskService.cs 프로젝트: zamis/LiteDB
        /// <summary>
        /// Create a new empty database (use synced mode)
        /// </summary>
        private void Initialize(Stream stream, Collation collation, long initialSize)
        {
            var buffer = new PageBuffer(new byte[PAGE_SIZE], 0, 0);
            var header = new HeaderPage(buffer, 0);

            // update collation
            header.Pragmas.Set(Pragmas.COLLATION, (collation ?? Collation.Default).ToString(), false);

            // update buffer
            header.UpdateBuffer();

            stream.Write(buffer.Array, buffer.Offset, PAGE_SIZE);

            if (initialSize > 0)
            {
                if (stream is AesStream)
                {
                    throw LiteException.InitialSizeCryptoNotSupported();
                }
                if (initialSize % PAGE_SIZE != 0)
                {
                    throw LiteException.InvalidInitialSize();
                }
                stream.SetLength(initialSize);
            }

            stream.FlushToDisk();
        }