public void TestReadFrom3Chunks() { string filename = "read3chunks.txt"; int chunks = 3; int chunkSize = 256 * 1024; int size = (256 * 1024 * chunks) - 5000; Object id = CreateDummyFile(filename, size, chunkSize, 0); using (GridFileStream gfs = fs.OpenRead(filename)){ int buffsize = 10240; Byte[] buff = new Byte[buffsize]; int read = 0; int totalRead = 0; while ((read = gfs.Read(buff, 0, buffsize)) != 0) { totalRead += read; } Assert.AreEqual(size, totalRead, "Not all bytes read back"); } }
public void TestRead() { string filename = "readme.txt"; GridFileStream gfs = fs.Create(filename); for (int i = 1; i <= 50; i++) { gfs.Write(BitConverter.GetBytes(i), 0, 4); } gfs.Close(); gfs = fs.OpenRead(filename); Byte[] buff = new Byte[4]; int read; for (int i = 1; i <= 50; i++) { read = gfs.Read(buff, 0, 4); Assert.AreEqual(4, read, "Not enough bytes were read"); Assert.AreEqual(i, BitConverter.ToInt32(buff, 0), "value read back was not the same as written"); } }
public void TestWriteWithMultipleFlushes() { string filename = "multiflush.txt"; GridFileStream gfs = fs.Create(filename); Object id = gfs.GridFileInfo.Id; int size = gfs.GridFileInfo.ChunkSize * 2; byte[] buff; int x = 0; for (int i = 0; i < size; i += 4) { buff = BitConverter.GetBytes(x); gfs.Write(buff, 0, buff.Length); x++; if (i % size / 4 == 0) { gfs.Flush(); } } gfs.Close(); gfs = fs.OpenRead(filename); int read; int val; buff = new byte[4]; for (int i = 0; i < size / 4; i++) { read = gfs.Read(buff, 0, 4); val = BitConverter.ToInt32(buff, 0); Assert.AreEqual(4, read, "Not enough bytes were read. Pos: " + gfs.Position); Assert.AreEqual(i, val, "value read back was not the same as written. Pos: " + gfs.Position); } }
public GridFileStream Open(FileMode mode, FileAccess access) { switch (mode) { case FileMode.Create: if(gridFile.Exists(this.FileName) == true){ return this.Open(FileMode.Truncate, access); }else{ return this.Create(FileMode.CreateNew, access); } case FileMode.CreateNew: return this.Create(mode, access); case FileMode.Open: LoadFileData(); return new GridFileStream(this,this.gridFile.Files, this.gridFile.Chunks, access); case FileMode.OpenOrCreate: if(gridFile.Exists(this.FileName) == false) return this.Create(mode, access); LoadFileData(); return new GridFileStream(this, this.gridFile.Files, this.gridFile.Chunks, access); case FileMode.Truncate: this.Truncate(); return new GridFileStream(this,this.gridFile.Files, this.gridFile.Chunks, access); case FileMode.Append: LoadFileData(); GridFileStream gfs = new GridFileStream(this,this.gridFile.Files, this.gridFile.Chunks, access); gfs.Seek(0,SeekOrigin.End); return gfs; } throw new NotImplementedException("Mode not implemented."); }