Base: apply clang format
This commit is contained in:
@@ -31,7 +31,7 @@ using zipios::FileCollection;
|
||||
using zipios::ZipHeader;
|
||||
|
||||
|
||||
ZipHeader::ZipHeader(std::istream &inp, int s_off, int e_off)
|
||||
ZipHeader::ZipHeader(std::istream& inp, int s_off, int e_off)
|
||||
: _input(inp)
|
||||
, _vs(s_off, e_off)
|
||||
{
|
||||
@@ -39,7 +39,7 @@ ZipHeader::ZipHeader(std::istream &inp, int s_off, int e_off)
|
||||
}
|
||||
|
||||
/** Create a copy of this instance. */
|
||||
FileCollection *ZipHeader::clone() const
|
||||
FileCollection* ZipHeader::clone() const
|
||||
{
|
||||
return new ZipHeader(*this);
|
||||
}
|
||||
@@ -49,28 +49,34 @@ void ZipHeader::close()
|
||||
_valid = false;
|
||||
}
|
||||
|
||||
std::istream *ZipHeader::getInputStream(const ConstEntryPointer &entry)
|
||||
std::istream* ZipHeader::getInputStream(const ConstEntryPointer& entry)
|
||||
{
|
||||
if (!_valid)
|
||||
if (!_valid) {
|
||||
throw zipios::InvalidStateException("Attempt to use an invalid FileCollection");
|
||||
}
|
||||
return getInputStream(entry->getName());
|
||||
}
|
||||
|
||||
std::istream *ZipHeader::getInputStream(const std::string &entry_name, MatchPath matchpath)
|
||||
std::istream* ZipHeader::getInputStream(const std::string& entry_name, MatchPath matchpath)
|
||||
{
|
||||
if (!_valid)
|
||||
if (!_valid) {
|
||||
throw zipios::InvalidStateException("Attempt to use an invalid ZipHeader");
|
||||
}
|
||||
|
||||
zipios::ConstEntryPointer ent = getEntry(entry_name, matchpath);
|
||||
|
||||
if (!ent)
|
||||
if (!ent) {
|
||||
return nullptr;
|
||||
else
|
||||
return new zipios::ZipInputStream(_input,
|
||||
static_cast<const zipios::ZipCDirEntry *>(ent.get())->getLocalHeaderOffset() + _vs.startOffset());
|
||||
}
|
||||
else {
|
||||
return new zipios::ZipInputStream(
|
||||
_input,
|
||||
static_cast<const zipios::ZipCDirEntry*>(ent.get())->getLocalHeaderOffset()
|
||||
+ _vs.startOffset());
|
||||
}
|
||||
}
|
||||
|
||||
bool ZipHeader::init(std::istream &_zipfile)
|
||||
bool ZipHeader::init(std::istream& _zipfile)
|
||||
{
|
||||
// Check stream error state
|
||||
if (!_zipfile) {
|
||||
@@ -82,11 +88,12 @@ bool ZipHeader::init(std::istream &_zipfile)
|
||||
return _valid;
|
||||
}
|
||||
|
||||
bool ZipHeader::readCentralDirectory(std::istream &_zipfile)
|
||||
bool ZipHeader::readCentralDirectory(std::istream& _zipfile)
|
||||
{
|
||||
// Find and read eocd.
|
||||
if (!readEndOfCentralDirectory(_zipfile))
|
||||
if (!readEndOfCentralDirectory(_zipfile)) {
|
||||
throw zipios::FCollException("Unable to find zip structure: End-of-central-directory");
|
||||
}
|
||||
|
||||
// Position read pointer to start of first entry in central dir.
|
||||
_vs.vseekg(_zipfile, _eocd.offset(), std::ios::beg);
|
||||
@@ -95,16 +102,22 @@ bool ZipHeader::readCentralDirectory(std::istream &_zipfile)
|
||||
// Giving the default argument in the next line to keep Visual C++ quiet
|
||||
_entries.resize(_eocd.totalCount(), nullptr);
|
||||
while ((entry_num < _eocd.totalCount())) {
|
||||
zipios::ZipCDirEntry *ent = new zipios::ZipCDirEntry;
|
||||
zipios::ZipCDirEntry* ent = new zipios::ZipCDirEntry;
|
||||
_entries[entry_num] = ent;
|
||||
_zipfile >> *ent;
|
||||
if (!_zipfile) {
|
||||
if (_zipfile.bad())
|
||||
throw zipios::IOException("Error reading zip file while reading zip file central directory");
|
||||
else if (_zipfile.fail())
|
||||
throw zipios::FCollException("Zip file consistency problem. Failure while reading zip file central directory");
|
||||
else if (_zipfile.eof())
|
||||
throw zipios::IOException("Premature end of file while reading zip file central directory");
|
||||
if (_zipfile.bad()) {
|
||||
throw zipios::IOException(
|
||||
"Error reading zip file while reading zip file central directory");
|
||||
}
|
||||
else if (_zipfile.fail()) {
|
||||
throw zipios::FCollException("Zip file consistency problem. Failure while reading "
|
||||
"zip file central directory");
|
||||
}
|
||||
else if (_zipfile.eof()) {
|
||||
throw zipios::IOException(
|
||||
"Premature end of file while reading zip file central directory");
|
||||
}
|
||||
}
|
||||
++entry_num;
|
||||
}
|
||||
@@ -114,18 +127,22 @@ bool ZipHeader::readCentralDirectory(std::istream &_zipfile)
|
||||
int pos = _vs.vtellg(_zipfile);
|
||||
_vs.vseekg(_zipfile, 0, std::ios::end);
|
||||
int remaining = static_cast<int>(_vs.vtellg(_zipfile)) - pos;
|
||||
if (remaining != _eocd.eocdOffSetFromEnd())
|
||||
throw zipios::FCollException("Zip file consistency problem. Zip file data fields are inconsistent with zip file layout");
|
||||
if (remaining != _eocd.eocdOffSetFromEnd()) {
|
||||
throw zipios::FCollException("Zip file consistency problem. Zip file data fields are "
|
||||
"inconsistent with zip file layout");
|
||||
}
|
||||
|
||||
// Consistency check 2, are local headers consistent with
|
||||
// cd headers
|
||||
if (!confirmLocalHeaders(_zipfile))
|
||||
throw zipios::FCollException("Zip file consistency problem. Zip file data fields are inconsistent with zip file layout");
|
||||
if (!confirmLocalHeaders(_zipfile)) {
|
||||
throw zipios::FCollException("Zip file consistency problem. Zip file data fields are "
|
||||
"inconsistent with zip file layout");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ZipHeader::readEndOfCentralDirectory(std::istream &_zipfile)
|
||||
bool ZipHeader::readEndOfCentralDirectory(std::istream& _zipfile)
|
||||
{
|
||||
zipios::BackBuffer bb(_zipfile, _vs);
|
||||
int read_p = -1;
|
||||
@@ -147,14 +164,14 @@ bool ZipHeader::readEndOfCentralDirectory(std::istream &_zipfile)
|
||||
return found;
|
||||
}
|
||||
|
||||
bool ZipHeader::confirmLocalHeaders(std::istream &_zipfile)
|
||||
bool ZipHeader::confirmLocalHeaders(std::istream& _zipfile)
|
||||
{
|
||||
zipios::Entries::const_iterator it;
|
||||
zipios::ZipCDirEntry *ent{};
|
||||
zipios::ZipCDirEntry* ent {};
|
||||
int inconsistencies = 0;
|
||||
zipios::ZipLocalEntry zlh;
|
||||
for (it = _entries.begin(); it != _entries.end(); ++it) {
|
||||
ent = static_cast<zipios::ZipCDirEntry *>((*it).get());
|
||||
ent = static_cast<zipios::ZipCDirEntry*>((*it).get());
|
||||
_vs.vseekg(_zipfile, ent->getLocalHeaderOffset(), std::ios::beg);
|
||||
_zipfile >> zlh;
|
||||
if (!_zipfile || zlh != *ent) {
|
||||
|
||||
Reference in New Issue
Block a user