splitting stream data
-
hi im just looking for a simple way to split the data of a file say 7600kb long (or any length) into x amount of 1000kb pieces. The problem im having is toward the end of the file 1000kb will not divide into 7600kb evenly. aggh another complicated problem with a easy solution that i obviously dont know the anwser to. Jesse
-
hi im just looking for a simple way to split the data of a file say 7600kb long (or any length) into x amount of 1000kb pieces. The problem im having is toward the end of the file 1000kb will not divide into 7600kb evenly. aggh another complicated problem with a easy solution that i obviously dont know the anwser to. Jesse
Here's a typical stream read loop that will copy from src to dest streams:
const int bufferSize = 4096;
byte[] buffer = new byte[bufferSize];int readBytes;
while ((readBytes = src.Read(buffer, 0, buffer.Length)) != 0)
{
dest.Write(buffer, 0, readBytes);
}Notice what I'm doing up there: the number of bytes read will be kept on the readBytes variable. So, instead of writing bufferSize bytes (which is always 4kb), I write only what I read - although I asked to read bufferSize, sometimes, it will be lower. The loop stops reading when src.Read returns zero, as there's no more data on the stream to be read. Your algorithm will need to do something similar to this - actually, if you don't want to use a 1000Kb buffer, it'll be a bit more complicated, but I hope you got the idea. Yes, even I am blogging now!
-
Here's a typical stream read loop that will copy from src to dest streams:
const int bufferSize = 4096;
byte[] buffer = new byte[bufferSize];int readBytes;
while ((readBytes = src.Read(buffer, 0, buffer.Length)) != 0)
{
dest.Write(buffer, 0, readBytes);
}Notice what I'm doing up there: the number of bytes read will be kept on the readBytes variable. So, instead of writing bufferSize bytes (which is always 4kb), I write only what I read - although I asked to read bufferSize, sometimes, it will be lower. The loop stops reading when src.Read returns zero, as there's no more data on the stream to be read. Your algorithm will need to do something similar to this - actually, if you don't want to use a 1000Kb buffer, it'll be a bit more complicated, but I hope you got the idea. Yes, even I am blogging now!