[Mono-dev] FileStream write bug
andrii.nakryiko at gmail.com
Wed Apr 10 09:50:28 UTC 2013
We've had a problems with FileStream under Mono (different versions, both
2.10.x and 3.0.x). It seems like some internal positioning problem, because
instead of overwriting some parts of file, it just appends written data. It
is very critical that the amount of bytes written is larger than internal
buffer size. I've managed to create small isolated test case that shows
both what is necessary for bug to occur and easy workaround for that. But
hopefully this will be fixed as this is core functionality.
I've filed a bug report here:
public class mono_filestream_bug
public void show_time()
const int pos = 1;
const int bufferSize = 128;
var filename = Path.GetTempFileName();
File.WriteAllBytes(filename, new byte[pos + 1]); // init file
var bytes = new byte[bufferSize + 1 /* THIS IS WHAT MAKES A BIG
using (var file = new FileStream(filename, FileMode.Open,
file.Read(new byte[pos], 0, pos); // THIS READ IS CRITICAL,
WITHOUT IT EVERYTHING WORKS
Assert.AreEqual(pos, file.Position); // !!! here it says
position is correct, but writes at different position !!!
// file.Position = pos; // !!! this fixes test !!!
file.Write(bytes, 0, bytes.Length);
//Assert.AreEqual(pos + bytes.Length, file.Length); -- fails
using (var filestream = File.Open(filename, FileMode.Open,
var bb = new byte[bytes.Length];
filestream.Position = pos;
filestream.Read(bb, 0, bb.Length);
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Mono-devel-list