xref: /haiku/src/apps/haikudepot/tar/TarArchiveHeader.h (revision 6e82e428596071bbde44e296d04740f1f5d54d03)
1 /*
2  * Copyright 2017, Andrew Lindesay <apl@lindesay.co.nz>.
3  * All rights reserved. Distributed under the terms of the MIT License.
4  */
5 
6 #ifndef TAR_ARCHIVE_HEADER_H
7 #define TAR_ARCHIVE_HEADER_H
8 
9 #include <String.h>
10 
11 
12 enum tar_file_type {
13 	TAR_FILE_TYPE_NORMAL,
14 	TAR_FILE_TYPE_OTHER
15 };
16 
17 
18 /* Each file in a tar-archive has a header on it describing the next entry in
19  * the stream.  This class models the data in the header.
20  */
21 
22 class TarArchiveHeader {
23 public:
24 									TarArchiveHeader(const BString& fileName,
25 										uint64 length, tar_file_type fileType);
26 
27 		static TarArchiveHeader*	CreateFromBlock(const unsigned char *block);
28 
29 			const BString&			GetFileName() const;
30 			size_t					GetLength() const;
31 			tar_file_type			GetFileType() const;
32 
33 private:
34 		static uint32				_CalculateChecksum(
35 										const unsigned char* data);
36 		static const BString		_ReadString(const unsigned char* data,
37 										size_t dataLength);
38 		static uint32				_ReadNumeric(const unsigned char* data,
39 										size_t dataLength);
40 		static tar_file_type		_ReadFileType(unsigned char data);
41 
42 			const BString			fFileName;
43 			uint64					fLength;
44 			tar_file_type			fFileType;
45 
46 };
47 
48 #endif // TAR_ARCHIVE_HEADER_H
49