OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 public: | 60 public: |
61 explicit TarGenerator(StreamProcessor *callback_client) | 61 explicit TarGenerator(StreamProcessor *callback_client) |
62 : callback_client_(callback_client), | 62 : callback_client_(callback_client), |
63 data_block_buffer_(TAR_BLOCK_SIZE), // initialized to zeroes | 63 data_block_buffer_(TAR_BLOCK_SIZE), // initialized to zeroes |
64 data_buffer_stream_(data_block_buffer_, TAR_BLOCK_SIZE) {} | 64 data_buffer_stream_(data_block_buffer_, TAR_BLOCK_SIZE) {} |
65 | 65 |
66 virtual ~TarGenerator() { Finalize(); } | 66 virtual ~TarGenerator() { Finalize(); } |
67 | 67 |
68 // Call AddFile() for each file entry, followed by calls to AddFileBytes() | 68 // Call AddFile() for each file entry, followed by calls to AddFileBytes() |
69 // for the file's data | 69 // for the file's data |
70 virtual void AddFile(const String &file_name, | 70 virtual bool AddFile(const String &file_name, |
Chris Rogers
2009/07/21 19:14:28
add comment about return value
| |
71 size_t file_size); | 71 size_t file_size); |
72 | 72 |
73 // Call to "push" bytes to be processed - our client will get called back | 73 // Call to "push" bytes to be processed - our client will get called back |
74 // with the byte stream, with files rounded up to the nearest block size | 74 // with the byte stream, with files rounded up to the nearest block size |
75 // (with zero padding) | 75 // (with zero padding) |
76 virtual int AddFileBytes(MemoryReadStream *stream, size_t n); | 76 virtual int AddFileBytes(MemoryReadStream *stream, size_t n); |
77 | 77 |
78 // Must call this after all files and file data have been written | 78 // Must call this after all files and file data have been written |
79 virtual void Finalize(); | 79 virtual void Finalize(); |
80 | 80 |
81 private: | 81 private: |
82 void AddEntry(const String &file_name, | 82 bool AddEntry(const String &file_name, |
Chris Rogers
2009/07/21 19:14:28
add comment about return value
| |
83 size_t file_size, | 83 size_t file_size, |
84 bool is_directory); | 84 bool is_directory); |
85 | 85 |
86 void AddDirectory(const String &file_name); | 86 bool AddDirectory(const String &file_name); |
Chris Rogers
2009/07/21 19:14:28
comment about return value
| |
87 void AddDirectoryEntryIfNeeded(const String &file_name); | 87 bool AddDirectoryEntryIfNeeded(const String &file_name); |
88 | 88 |
89 // Checksum for each header | 89 // Checksum for each header |
90 void ComputeCheckSum(uint8 *header); | 90 void ComputeCheckSum(uint8 *header); |
91 | 91 |
92 // Writes a head block. | |
93 void WriteHeader(const String& filename, | |
94 size_t file_size, | |
95 char type, | |
96 int mode, | |
97 int user_id, | |
98 int group_id, | |
99 int mod_time); | |
100 | |
92 // flushes buffered file data to the client callback | 101 // flushes buffered file data to the client callback |
93 // if |flush_padding_zeroes| is |true| then flush a complete block | 102 // if |flush_padding_zeroes| is |true| then flush a complete block |
94 // with zero padding even if less was buffered | 103 // with zero padding even if less was buffered |
95 void FlushDataBuffer(bool flush_padding_zeroes); | 104 void FlushDataBuffer(bool flush_padding_zeroes); |
96 | 105 |
97 enum {TAR_HEADER_SIZE = 512}; | 106 enum {TAR_HEADER_SIZE = 512}; |
98 enum {TAR_BLOCK_SIZE = 512}; | 107 enum {TAR_BLOCK_SIZE = 512}; |
99 | 108 |
100 StreamProcessor *callback_client_; | 109 StreamProcessor *callback_client_; |
101 | 110 |
(...skipping 14 matching lines...) Expand all Loading... | |
116 typedef std::map<const std::string, bool, StrCmp> DirectoryMap; | 125 typedef std::map<const std::string, bool, StrCmp> DirectoryMap; |
117 | 126 |
118 DirectoryMap directory_map_; | 127 DirectoryMap directory_map_; |
119 | 128 |
120 DISALLOW_COPY_AND_ASSIGN(TarGenerator); | 129 DISALLOW_COPY_AND_ASSIGN(TarGenerator); |
121 }; | 130 }; |
122 | 131 |
123 } // namespace o3d | 132 } // namespace o3d |
124 | 133 |
125 #endif // O3D_IMPORT_CROSS_TAR_GENERATOR_H_ | 134 #endif // O3D_IMPORT_CROSS_TAR_GENERATOR_H_ |
OLD | NEW |