- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
static void JoinFiles(string FileOne, string FileTwo, string Out)
{
//declare head size
const long HeadSize = sizeof(long) * 4;
//get files size
long FFS = (new FileInfo(FileOne).Length),
SFS = (new FileInfo(FileTwo).Length);
//Full paths of files
string FFFN = Path.GetFileName(Path.GetFullPath(FileOne)),
SFFN = Path.GetFileName(Path.GetFullPath(FileTwo));
//calculate offsets
long FirstFileOffset = HeadSize + FFFN.Length,
FirstFileNameOffset = HeadSize,
SecondFileNameOffset = FirstFileOffset + FFS,
SecondFileOffset = SecondFileNameOffset + SFFN.Length;
//declare head
byte[] Head = new byte[HeadSize];
/*
* FFO FFNO SFO SFNO
*/
//Format head
Head = JoinArrays<byte>(BitConverter.GetBytes(FirstFileOffset),
BitConverter.GetBytes(FirstFileNameOffset),
BitConverter.GetBytes(SecondFileOffset),
BitConverter.GetBytes(SecondFileNameOffset));
//declare streams
System.IO.BinaryReader FBR = new BinaryReader(File.OpenRead(FileOne));
System.IO.BinaryWriter BW = new System.IO.BinaryWriter(File.Create(Out));
//Write head information
foreach (byte b in Head) BW.Write(b);
//Write first file name
byte[] buffer = System.Text.ASCIIEncoding.ASCII.GetBytes(FFFN);
BW.Write(buffer, 0, buffer.Length);
//Write first file
for (long id = 0; id < FFS; id++) BW.Write(FBR.ReadByte());
//Write second file name
buffer = System.Text.ASCIIEncoding.ASCII.GetBytes(SFFN);
BW.Write(buffer, 0, buffer.Length);
//Open second file
FBR.Close();
FBR = new BinaryReader(File.OpenRead(FileTwo));
//Write second file
for (long id = 0; id < SFS; id++) BW.Write(FBR.ReadByte());
//Save result
BW.Flush();
//Close streams
FBR.Close();
BW.Close();
}
Функция склеивания двух файлов. Писал вчера вечером, когда утром посмотрел, я понял что писал я это очень поздно.