ZIP-архив

В этой статье описывается устройтво формата ZIP.

Файл состоит из трех частей: заголовка, данных (файлов) и таблицы файлов.

Заголовой архива распологается в самом его конце и имеет вид:

struct ZIP_CENTDIREND {
	DWORD sign;			// end of central dir signature    4 bytes  (0x06054b50)
	WORD disknum;		// number of this disk             2 bytes
	WORD diskcdstart;	// number of the disk with the
						// start of the central directory  2 bytes
	WORD countcddisk;	// total number of entries in the
						// central directory on this disk  2 bytes
	WORD countcd;		// total number of entries in
						// the central directory           2 bytes
	DWORD cdsize;		// size of the central directory   4 bytes
	DWORD cdoffset;		// offset of start of central
						// directory with respect to
						// the starting disk number        4 bytes
	WORD lencomm;		// .ZIP file comment length        2 bytes
};

Непостредственно перед заголовком находится таблица файлов (Central directory). Она состоит из набора записей формата:

struct ZIP_CENTDIRFILE {
	DWORD sign;			// central file header signature   4 bytes  (0x02014b50)
	WORD vermade;		// version made by                 2 bytes
	WORD ver;			// version needed to extract       2 bytes
	WORD flags;			// general purpose bit flag        2 bytes
	WORD compr;			// compression method              2 bytes
	WORD lastmodtime;	// last mod file time              2 bytes
	WORD lastmoddate;	// last mod file date              2 bytes
	DWORD crc32;		// crc-32                          4 bytes
	DWORD sizecompr;	// compressed size                 4 bytes
	DWORD sizeorig;		// uncompressed size               4 bytes
	WORD lenname;		// file name length                2 bytes
	WORD lenextr;		// extra field length              2 bytes
	WORD lencomm;		// file comment length             2 bytes
	WORD disknum;		// disk number start               2 bytes
	WORD intattr;		// internal file attributes        2 bytes
	DWORD extattr;		// external file attributes        4 bytes
	DWORD offset;		// relative offset of local header 4 bytes
};

От начала архиво и вплоть до таблицы файлов находятся сами данные. Запись каждого файла состоит из заголовка и непостредственно данных. Локальный заголовок файла имеет вид:

struct ZIP_LOCALFILEHDR {
	DWORD sign;			// local file header signature     4 bytes  (0x04034b50)
	WORD ver;			// version needed to extract       2 bytes
	WORD flags;			// general purpose bit flag        2 bytes
	WORD compr;			// compression method              2 bytes
	WORD lastmodtime;	// last mod file time              2 bytes
	WORD lastmoddate;	// last mod file date              2 bytes
	DWORD crc32;		// crc-32                          4 bytes
	DWORD sizecompr;	// compressed size                 4 bytes
	DWORD sizeorig;		// uncompressed size               4 bytes
	WORD lenname;		// file name length                2 bytes
	WORD lenextr;		// extra field length              2 bytes
};

Сайт создан исключительно в образовательных целях. По всем вопросам с администрацией сайта можно связаться по электронной почте admin@dcsr.ru. Вход для редактора.