public override void FlushBuffer(byte[] b, int offset, int len)
        {
            var segment = new byte[len];

            Buffer.BlockCopy(b, offset, segment, 0, len);

            var fsinfo = _db.FileStorage.FindById(_name);

            if (fsinfo != null)
            {
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    //Console.WriteLine($"{fsinfo.Id} already exist with lenth of {fsinfo.GetContentFileDataLength}");
                    fsinfo.CopyTo(memoryStream);
                    //memoryStream.Position = memoryStream.GetContentFileDataLength;
                    memoryStream.Position = FilePointer - len;
                    //Console.WriteLine($"MemorySteam lenth: {memoryStream.GetContentFileDataLength} before writing");
                    memoryStream.Write(segment, 0, len);
                    //memoryStream.Flush();
                    //_db.FileStorage.Delete(_name);
                    //Console.WriteLine($"MemorySteam lenth: {memoryStream.GetContentFileDataLength} after writing and flush");
                    memoryStream.Position = 0;
                    fsinfo = _db.FileStorage.Upload(_name, _name, memoryStream);
                    //Console.WriteLine($"{_name} lenth {fsinfo.GetContentFileDataLength} after flush");
                }
            }
            else
            {
                using (LiteFileStream fileStream = _db.FileStorage.OpenWrite(_name, _name))
                {
                    //Console.WriteLine($"Opened a new file:{_name} to write.");
                    fileStream.Write(segment, 0, len);
                    fileStream.Flush();
                    //Console.WriteLine($"{_name} lenth {fileStream.GetContentFileDataLength} after flush");
                }
            }
            GC.Collect();
        }
Ejemplo n.º 2
0
        private void Write(byte[] buffer, int index, int len, bool isFirstWrite)
        {
            var fsinfo = _db.FileStorage.FindById(_name);

            if (fsinfo != null)
            {
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    //Console.WriteLine($"{fsinfo.Id} already exist with lenth of {fsinfo.Length}");
                    fsinfo.CopyTo(memoryStream);
                    //memoryStream.Position = memoryStream.Length;
                    memoryStream.Position = index;
                    //Console.WriteLine($"MemorySteam lenth: {memoryStream.Length} before writing");
                    memoryStream.Write(buffer, 0, len);
                    //memoryStream.Flush();
                    //_db.FileStorage.Delete(_name);
                    //Console.WriteLine($"MemorySteam lenth: {memoryStream.Length} after writing and flush");
                    memoryStream.Position = 0;
                    fsinfo = _db.FileStorage.Upload(_name, _name, memoryStream);
                    //Console.WriteLine($"{_name} lenth {fsinfo.Length} after flush");
                }
            }
            else
            {
                using (LiteFileStream fileStream = _db.FileStorage.OpenWrite(_name, _name))
                {
                    //Console.WriteLine($"Opened a new file:{_name} to write.");
                    fileStream.Write(buffer, 0, len);
                    fileStream.Flush();
                    //Console.WriteLine($"{_name} lenth {fileStream.Length} after flush");
                }
            }
            GC.Collect();


            //Console.WriteLine($"---------------------------------------");
        }