I have to format the description and source code for the 7z archive format, but I still have trouble writing a Valid Container I think I can make an empty container ... even though I'm starting:
std :: ofstream ofs (archivename.c_str (), std :: ios :: Binary | std :: Ios :: TRUNC); Byte signature [6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}; Byte key = 0; Byte minor = 3; Ofs.write ((const char *) sign, 6); Ofs.write ((const char *) Head, 1); Ofs.write ((const char *) minor, 1); UInt64 offset = 0; UInt64 size = 0; UInt32 CRC = 0; Ofs.write ((const char *) offset, 4); Ofs.write ((const char *) size, 8); Ofs.write ((const char *) CRC, 8); Ofs.write ((const char *) CrcCalc (0, 0), 8); Ofs.close ();
I think my main problem is lack of understanding of std :: ofstream :: write (). Byte is an 'unsigned char', UInt64 & amp; UInt32 both are 'unsigned long'
UPDATE0 : As everyone says, this would be a big problem if I went to the big-endian machine, this is not the case here According to Fredrik Jensen, I should cast a non-array address. I should also mention that there is a function in the CRCALC (LGMI SDK). Adding & amp;
UPDATE1 : The working code below to get an empty archive file.
Fixed Zero SetUInt32 (Byte * P, UInt32D) {for (int i = 0; i > = 8) P [I] = (byte) d; } Static Zero SetUInt64 (Byte * P, UINT64D) {For (Int i = 0; I <8; I ++, D>> = 8) P [I] = (byte) D; } Zero Make_7 z_archive () {CrcGenerateTable (); Std :: ofstream ofs (archivename.c_str (), std :: ios :: binary | std :: ios :: trunc); Byte signature [6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}; Byte key = 0; Byte minor = 3; Ofs.write ((const char *) sign, 6); Ofs.write ((const char *) & Head, 1); Ofs.write ((const char *) and minor, 1); UInt64 offset = 0; UInt64 size = 0; UInt32 CRC = 0; Byte buff [24]; SetUInt64 (buf + 4, offset); SetUInt64 (buf + 12, size); SetUInt32 (Buff + 20, CRC); SetUInt32 (Buff, CRCALC (Buff + 4, 20)); Ofs.write ((const char *) buf, 24); Ofs.close (); }
Note: CrcGenerateTable () and CrcCalc () are from the LZMA SDK.
7z format is not known, but I think that when you write offset, size and CRC , Then this file will be written in a slightly-end format (I think you have a small-endian CPU).
EDIT: One is probably bad, you & amp; Before major, minor, offset, size and CRC, that is, you are casting the actual value into an indicator.
Comments
Post a Comment