⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testblob.cs

📁 Perst开源实时数据库
💻 CS
字号:
#define LARGE_FILE_TEST

using System;
using Perst;
using System.IO;

public class TestBlob 
{ 
    public static void Main(string[] args) 
    { 
        Storage db = StorageFactory.Instance.CreateStorage();
        db.Open("testblob.dbs");
        byte[] buf = new byte[1024];
        int rc;

#if LARGE_FILE_TEST
        FileStream fs = new FileStream("\\Perst.NET\\src\\impl\\dummy.cs", FileMode.Create);
        const long LargeFileSize = 128*1024*1024;
        byte bn = 0;
        for (long size = 0; size < LargeFileSize; size += buf.Length) {
             for (int i = 0; i < buf.Length; i++) { 
                 buf[i] = bn;
             }
             fs.Write(buf, 0, buf.Length);
             bn +=1;
        }
        fs.Close();
#endif
        

        string[] files = Directory.GetFiles("\\Perst.NET\\src\\impl", "*.cs");
#if USE_GENERICS
        Index<string,Blob> root = (Index<string,Blob>)db.Root;
#else
        Index root = (Index)db.Root;
#endif
        if (root == null) 
        { 
#if USE_GENERICS
            root = db.CreateIndex<string,Blob>(true);
#else
            root = db.CreateIndex(typeof(string), true);
#endif
            db.Root = root;
            foreach (string file in files) 
            { 
                FileStream fin = new FileStream(file, FileMode.Open, FileAccess.Read);
                Blob blob = db.CreateBlob();                    
                Stream bout = blob.GetStream();
                while ((rc = fin.Read(buf, 0, buf.Length)) > 0) 
                { 
                    bout.Write(buf, 0, rc);
                }
                root[file] = blob; 
                fin.Close();
                bout.Close();   
            }
            Console.WriteLine("Database is initialized");
        } 
        foreach (string file in files) 
        {
            byte[] buf2 = new byte[1024];
#if USE_GENERICS
            Blob blob = root[file];
#else
            Blob blob = (Blob)root[file];
#endif
            if (blob == null) 
            {
                Console.WriteLine("File " + file + " not found in database");
                continue;
            }
            Stream bin = blob.GetStream();
            FileStream fin = new FileStream(file, FileMode.Open, FileAccess.Read);
            while ((rc = fin.Read(buf, 0, buf.Length)) > 0) 
            { 
                int rc2 = bin.Read(buf2, 0, buf2.Length);
                if (rc != rc2) 
                {
                    Console.WriteLine("Different file size: " + rc + " .vs. " + rc2);
                    break;
                }
                while (--rc >= 0 && buf[rc] == buf2[rc]);
                if (rc >= 0) 
                { 
                    Console.WriteLine("Content of the files is different: " + buf[rc] + " .vs. " + buf2[rc]);
                    break;
                }
            }
            fin.Close();
            bin.Close();
        }            
        Console.WriteLine("Verification completed");
        db.Close();
#if LARGE_FILE_TEST
        File.Delete("\\Perst.NET\\src\\impl\\dummy.cs");
#endif
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -