| 1 | // |
| 2 | // ZipDataInfo.cpp |
| 3 | // |
| 4 | // Library: Zip |
| 5 | // Package: Zip |
| 6 | // Module: ZipDataInfo |
| 7 | // |
| 8 | // Copyright (c) 2007, Applied Informatics Software Engineering GmbH. |
| 9 | // and Contributors. |
| 10 | // |
| 11 | // SPDX-License-Identifier: BSL-1.0 |
| 12 | // |
| 13 | |
| 14 | |
| 15 | #include "Poco/Zip/ZipDataInfo.h" |
| 16 | #include "Poco/Exception.h" |
| 17 | #include <istream> |
| 18 | #include <cstring> |
| 19 | |
| 20 | |
| 21 | namespace Poco { |
| 22 | namespace Zip { |
| 23 | |
| 24 | |
| 25 | const char ZipDataInfo::[ZipCommon::HEADER_SIZE] = {'\x50', '\x4b', '\x07', '\x08'}; |
| 26 | |
| 27 | |
| 28 | ZipDataInfo::ZipDataInfo(): |
| 29 | _rawInfo(), |
| 30 | _valid(true) |
| 31 | { |
| 32 | std::memcpy(_rawInfo, HEADER, ZipCommon::HEADER_SIZE); |
| 33 | std::memset(_rawInfo+ZipCommon::HEADER_SIZE, 0, FULLHEADER_SIZE - ZipCommon::HEADER_SIZE); |
| 34 | _valid = true; |
| 35 | } |
| 36 | |
| 37 | |
| 38 | ZipDataInfo::ZipDataInfo(std::istream& in, bool ): |
| 39 | _rawInfo(), |
| 40 | _valid(false) |
| 41 | { |
| 42 | if (assumeHeaderRead) |
| 43 | { |
| 44 | std::memcpy(_rawInfo, HEADER, ZipCommon::HEADER_SIZE); |
| 45 | } |
| 46 | else |
| 47 | { |
| 48 | in.read(_rawInfo, ZipCommon::HEADER_SIZE); |
| 49 | if (in.gcount() != ZipCommon::HEADER_SIZE) |
| 50 | throw Poco::IOException("Failed to read data info header" ); |
| 51 | if (std::memcmp(_rawInfo, HEADER, ZipCommon::HEADER_SIZE) != 0) |
| 52 | throw Poco::DataFormatException("Bad data info header" ); |
| 53 | } |
| 54 | // now copy the rest of the header |
| 55 | in.read(_rawInfo+ZipCommon::HEADER_SIZE, FULLHEADER_SIZE - ZipCommon::HEADER_SIZE); |
| 56 | _valid = (!in.eof() && in.good()); |
| 57 | } |
| 58 | |
| 59 | |
| 60 | ZipDataInfo::~ZipDataInfo() |
| 61 | { |
| 62 | } |
| 63 | |
| 64 | |
| 65 | const char ZipDataInfo64::[ZipCommon::HEADER_SIZE] = {'\x50', '\x4b', '\x07', '\x08'}; |
| 66 | |
| 67 | |
| 68 | ZipDataInfo64::ZipDataInfo64(): |
| 69 | _rawInfo(), |
| 70 | _valid(true) |
| 71 | { |
| 72 | std::memcpy(_rawInfo, HEADER, ZipCommon::HEADER_SIZE); |
| 73 | std::memset(_rawInfo+ZipCommon::HEADER_SIZE, 0, FULLHEADER_SIZE - ZipCommon::HEADER_SIZE); |
| 74 | _valid = true; |
| 75 | } |
| 76 | |
| 77 | |
| 78 | ZipDataInfo64::ZipDataInfo64(std::istream& in, bool ): |
| 79 | _rawInfo(), |
| 80 | _valid(false) |
| 81 | { |
| 82 | if (assumeHeaderRead) |
| 83 | { |
| 84 | std::memcpy(_rawInfo, HEADER, ZipCommon::HEADER_SIZE); |
| 85 | } |
| 86 | else |
| 87 | { |
| 88 | in.read(_rawInfo, ZipCommon::HEADER_SIZE); |
| 89 | if (in.gcount() != ZipCommon::HEADER_SIZE) |
| 90 | throw Poco::IOException("Failed to read data info header" ); |
| 91 | if (std::memcmp(_rawInfo, HEADER, ZipCommon::HEADER_SIZE) != 0) |
| 92 | throw Poco::DataFormatException("Bad data info header" ); |
| 93 | } |
| 94 | |
| 95 | // now copy the rest of the header |
| 96 | in.read(_rawInfo+ZipCommon::HEADER_SIZE, FULLHEADER_SIZE - ZipCommon::HEADER_SIZE); |
| 97 | _valid = (!in.eof() && in.good()); |
| 98 | } |
| 99 | |
| 100 | |
| 101 | ZipDataInfo64::~ZipDataInfo64() |
| 102 | { |
| 103 | } |
| 104 | |
| 105 | |
| 106 | } } // namespace Poco::Zip |
| 107 | |