Skip to content

Instantly share code, notes, and snippets.

@jasonmbrown
Created August 4, 2017 11:02
Show Gist options
  • Save jasonmbrown/592fe9e6f9fd584701d727eca8e06282 to your computer and use it in GitHub Desktop.
Save jasonmbrown/592fe9e6f9fd584701d727eca8e06282 to your computer and use it in GitHub Desktop.
private int Split(string xcpFile, uint[] splitAt)
{
if (!File.Exists(xcpFile)) return 1;
using (FileStream rfs = new FileStream(xcpFile, FileMode.Open, FileAccess.Read, FileShare.Read))
{
byte[] buffer = new byte[4096];
long LeftToRead = 0;
int loop = 0;
foreach (uint readTo in splitAt)
{
string FilePath = Path.ChangeExtension(xcpFile, ".part" + Array.IndexOf(splitAt, readTo) + 1);
//if (readTo == 0) rfs.s;
LeftToRead = readTo - (buffer.Length * loop);
using (FileStream wfs = new FileStream(FilePath, FileMode.Create, FileAccess.Write))
{
loop = 0;
while (LeftToRead > 0)
{
loop += 1;
rfs.ReadAsync(buffer, 0, buffer.Length);
wfs.WriteAsync(buffer, 0, buffer.Length);
LeftToRead = readTo - (buffer.Length * loop);
}
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment