/// <summary> /// Shrink datafile /// </summary> public void Shrink() { var dbFileName = _fileStream.Name; var fileAccess = _fileStream.CanWrite ? FileAccess.ReadWrite : FileAccess.Read; var tempFile = Path.GetDirectoryName(dbFileName) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(dbFileName) + ".temp" + Path.GetExtension(dbFileName); if (File.Exists(tempFile)) { File.Delete(tempFile); } var entries = ListFiles(); FileDB.CreateEmptyFile(tempFile, false); using (var tempDb = new FileDB(tempFile, FileAccess.ReadWrite)) { foreach (var entry in entries) { using (var stream = new MemoryStream()) { Read(entry.ID, stream); stream.Seek(0, SeekOrigin.Begin); tempDb.Store(entry, stream); } } } Dispose(); File.Delete(dbFileName); File.Move(tempFile, dbFileName); Connect(dbFileName, fileAccess); }
public EntryInfo StoreFile(string fileToStore) { using (var db = new FileDB(_filedbPath, FileAccess.Write)) { return db.Store(fileToStore); } }
/// <summary> /// Store a file inside the database /// </summary> /// <param name="dbFileName">Database path/filname (eg: C:\Temp\MyDB.dat)</param> /// <param name="fileName">Filename to associate with file (eg: MyPhoto.jpg)</param> /// <param name="input">Stream with a file content</param> /// <returns>EntryInfo with file information</returns> public static EntryInfo Store(string dbFileName, string fileName, Stream input) { using (var db = new FileDB(dbFileName, FileAccess.ReadWrite)) { return(db.Store(fileName, input)); } }
/// <summary> /// Store a file inside the database /// </summary> /// <param name="dbFileName">Database path/filname (eg: C:\Temp\MyDB.dat)</param> /// <param name="fileName">Filename to associate with file (eg: MyPhoto.jpg)</param> /// <param name="input">Stream with a file content</param> /// <returns>EntryInfo with file information</returns> public static EntryInfo Store(string dbFileName, string fileName, Stream input) { using (var db = new FileDB(dbFileName, FileAccess.ReadWrite)) { return db.Store(fileName, input); } }
public static EntryInfo Store(string dbFileName, string fileName, byte[] inputBuffer) { using (MemoryStream ms = new MemoryStream(inputBuffer)) using (var db = new FileDB(dbFileName, FileAccess.ReadWrite)) { EntryInfo en = db.Store(fileName, ms); ms.Close(); return(en); } }
public static EntryInfo Store(string dbFileName, string fileName, byte[] inputBuffer) { using (MemoryStream ms = new MemoryStream(inputBuffer)) using (var db = new FileDB(dbFileName, FileAccess.ReadWrite)) { EntryInfo en = db.Store(fileName, ms); ms.Close(); return en; } }
static void Test2() { //------------------------------------------------------------------------------ string dbFileName = @"d:\\WImageTest\\testdb2.dat"; //EntryInfo[] fileList2 = FileDB.ListFiles(dbFileName); //var filename1 = fileList2[0].FileUrl; //1. open byte[] inputBuffer = GenerateTestDataBuffer("hello!...1"); List<SampleStoreRequest> storeReqs = new List<SampleStoreRequest>() { new SampleStoreRequest("a01", GenerateTestDataBuffer("hello_a01")), new SampleStoreRequest("a02", GenerateTestDataBuffer("hello_a02")), new SampleStoreRequest("a03", GenerateTestDataBuffer("hello_a03")), new SampleStoreRequest("a04", GenerateTestDataBuffer("hello_a04")), new SampleStoreRequest("a05", GenerateTestDataBuffer("hello_a05")) }; using (var db = new FileDB(dbFileName, FileAccess.ReadWrite)) { EntryInfo[] prevFiles = db.ListFiles(); int j = storeReqs.Count; for (int i = 0; i < j; ++i) { SampleStoreRequest req = storeReqs[i]; using (var dataStream = new MemoryStream(req.buffer)) { EntryInfo en = db.Store(req.fileName, dataStream); db.Flush(); } } } //------------------------------------------------------------------------------ //test read back EntryInfo[] fileList = FileDB.ListFiles(dbFileName); }
/// <summary> /// Shrink datafile /// </summary> public void Shrink() { var dbFileName = _fileStream.Name; var fileAccess = _fileStream.CanWrite ? FileAccess.ReadWrite : FileAccess.Read; var tempFile = Path.GetDirectoryName(dbFileName) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(dbFileName) + ".temp" + Path.GetExtension(dbFileName); if (File.Exists(tempFile)) File.Delete(tempFile); var entries = ListFiles(); FileDB.CreateEmptyFile(tempFile, false); using (var tempDb = new FileDB(tempFile, FileAccess.ReadWrite)) { foreach (var entry in entries) { using (var stream = new MemoryStream()) { Read(entry.ID, stream); stream.Seek(0, SeekOrigin.Begin); tempDb.Store(entry, stream); } } } Dispose(); File.Delete(dbFileName); File.Move(tempFile, dbFileName); Connect(dbFileName, fileAccess); }