private void updateFileHeaderInfo() { byte[] data = new byte[8]; //save the "allRecordsLength" value BitConverterEx.SetBytes(_allRecordsLength, data, 0); _fileStream.Seek(20, SeekOrigin.Begin); _fileStream.Write(data, 0, 8); _fileStream.Flush(); }
private void combineRecordHeader(byte[] header, int dataAreaLength, int contentLength, long nextRecordStartPosition) { //record header mark for (int idx = 0; idx < 4; idx++) { header[idx] = 0xff; } BitConverterEx.SetBytes(dataAreaLength, header, 4); BitConverterEx.SetBytes(contentLength, header, 8); BitConverterEx.SetBytes(nextRecordStartPosition, header, 12); }
/// <summary> /// Rebuild binary data file /// </summary> private static void RebuildDataFile(string dataFile) { FileStream stream = new FileStream( dataFile, FileMode.Create, FileAccess.Write); //the file header total length is 512 byte byte[] header = new byte[512]; string headerName = "KWY/TCD"; int headerVersion = 10; long headerAllRecordsLength = header.Length; BitConverterEx.SetBytes(headerName, header, 0, 16, Encoding.ASCII); //header segment: Name offset=0 BitConverterEx.SetBytes(headerVersion, header, 16); //header segment: Version offset=16 BitConverterEx.SetBytes(headerAllRecordsLength, header, 20); //header segment: AllRecordsLength offset=20 stream.Write(header, 0, header.Length); stream.Close(); }