74 void zipRead(std::istream& is, uint32_t& value)
76 unsigned char buf[
sizeof(value)];
78 if(!is.read(reinterpret_cast<char *>(buf),
sizeof(value)))
80 throw IOException(
"an I/O error while reading zip archive data from file.");
82 if(is.gcount() !=
sizeof(value))
84 throw IOException(
"EOF or an I/O error while reading zip archive data from file.");
95 void zipRead(std::istream& is, uint16_t& value)
97 unsigned char buf[
sizeof(value)];
99 if(!is.read(reinterpret_cast<char *>(buf),
sizeof(value)))
101 throw IOException(
"an I/O error while reading zip archive data from file.");
103 if(is.gcount() !=
sizeof(value))
105 throw IOException(
"EOF or an I/O error while reading zip archive data from file.");
109 value = (buf[0] << 0)
114 void zipRead(std::istream& is, uint8_t& value)
116 unsigned char buf[
sizeof(value)];
118 if(!is.read(reinterpret_cast<char *>(buf),
sizeof(value)))
120 throw IOException(
"an I/O error while reading zip archive data from file.");
122 if(is.gcount() !=
sizeof(value))
124 throw IOException(
"EOF or an I/O error while reading zip archive data from file.");
134 buffer.resize(count);
137 if(!is.read(reinterpret_cast<char *>(&buffer[0]), count))
139 throw IOException(
"an I/O error while reading zip archive data from file.");
141 if(is.gcount() != count)
143 throw IOException(
"EOF or an I/O error while reading zip archive data from file.");
149 void zipRead(std::istream& is, std::string& str, ssize_t
const count)
154 if(!is.read(reinterpret_cast<char *>(&str[0]), count))
156 throw IOException(
"an I/O error while reading zip archive data from file.");
158 if(is.gcount() != count)
160 throw IOException(
"EOF or an I/O error while reading zip archive data from file.");
168 if(pos +
sizeof(value) > is.size())
170 throw IOException(
"EOF reached while reading zip archive data from file.");
173 value = (is[pos + 0] << 0)
175 | (is[pos + 2] << 16)
176 | (is[pos + 3] << 24);
178 pos +=
sizeof(value);
184 if(pos +
sizeof(value) > is.size())
186 throw IOException(
"EOF reached while reading zip archive data from file.");
189 value = (is[pos + 0] << 0)
190 | (is[pos + 1] << 8);
192 pos +=
sizeof(value);
198 if(pos +
sizeof(value) > is.size())
200 throw IOException(
"EOF reached while reading zip archive data from file.");
205 pos +=
sizeof(value);
211 if(pos + count > is.size())
213 throw IOException(
"EOF reached while reading zip archive data from file.");
217 buffer.insert(buffer.begin(), is.begin() + pos, is.begin() + pos + count);
225 if(pos + count > is.size())
227 throw IOException(
"EOF reached while reading zip archive data from file.");
231 str.insert(str.begin(), is.begin() + pos, is.begin() + pos + count);
237 void zipWrite(std::ostream& os, uint32_t
const& value)
239 char buf[
sizeof(value)];
243 buf[2] = value >> 16;
244 buf[3] = value >> 24;
246 if(!os.write(buf,
sizeof(value)))
248 throw IOException(
"an I/O error occurred while writing to a zip archive file.");
253 void zipWrite(std::ostream& os, uint16_t
const& value)
255 char buf[
sizeof(value)];
260 if(!os.write(buf,
sizeof(value)))
262 throw IOException(
"an I/O error occurred while writing to a zip archive file.");
267 void zipWrite(std::ostream& os, uint8_t
const& value)
269 char buf[
sizeof(value)];
273 if(!os.write(buf,
sizeof(value)))
275 throw IOException(
"an I/O error occurred while writing to a zip archive file.");
282 if(!os.write(reinterpret_cast<char const *>(&buffer[0]), buffer.size()))
284 throw IOException(
"an I/O error occurred while writing to a zip archive file.");
289 void zipWrite(std::ostream& os, std::string
const& str)
291 if(!os.write(&str[0], str.length()))
293 throw IOException(
"an I/O error occurred while writing to a zip archive file.");
Various exceptions used throughout the Zipios++ library, all based on zipios::Exception.
void zipRead(std::istream &is, uint32_t &value)
void zipWrite(std::ostream &os, uint32_t const &value)
char const g_separator
The character used as the filename separator.
An IOException is used to signal an I/O error.
std::vector< unsigned char > buffer_t
A buffer of characters.
Various functions used throughout the library.