mirror of
https://github.com/pocoproject/poco.git
synced 2025-03-05 03:37:28 +01:00
style fixes
This commit is contained in:
parent
e2481c6c64
commit
a47e82a4c0
@ -5,14 +5,14 @@
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: Compress
|
||||
// Module: Compress
|
||||
//
|
||||
// Definition of the Compress class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
@ -42,7 +42,7 @@ public:
|
||||
/// seekableOut determines how we write the zip, setting it to true is recommended for local files (smaller zip file),
|
||||
/// if you are compressing directly to a network, you MUST set it to false
|
||||
/// If forceZip64 is set true then the file header is allocated with zip64 extension so that it can be updated after the file data is written
|
||||
/// if seekableOut is true in case the compressed or uncompressed size exceeds 32 bits.
|
||||
/// if seekableOut is true in case the compressed or uncompressed size exceeds 32 bits.
|
||||
|
||||
~Compress();
|
||||
|
||||
@ -80,10 +80,10 @@ public:
|
||||
/// leads to worse results. Extensions will be converted to lower case.
|
||||
///
|
||||
/// The default extensions are:
|
||||
/// - gif
|
||||
/// - jpg
|
||||
/// - jpeg
|
||||
/// - png
|
||||
/// - gif
|
||||
/// - jpg
|
||||
/// - jpeg
|
||||
/// - png
|
||||
|
||||
const std::set<std::string>& getStoreExtensions() const;
|
||||
/// Returns the file extensions for which the CM_STORE compression method
|
||||
@ -108,16 +108,16 @@ private:
|
||||
/// copys an already compressed ZipEntry from in
|
||||
|
||||
private:
|
||||
std::set<std::string> _storeExtensions;
|
||||
std::ostream& _out;
|
||||
bool _seekableOut;
|
||||
bool _forceZip64;
|
||||
ZipArchive::FileHeaders _files;
|
||||
ZipArchive::FileInfos _infos;
|
||||
ZipArchive::DirectoryInfos _dirs;
|
||||
std::set<std::string> _storeExtensions;
|
||||
std::ostream& _out;
|
||||
bool _seekableOut;
|
||||
bool _forceZip64;
|
||||
ZipArchive::FileHeaders _files;
|
||||
ZipArchive::FileInfos _infos;
|
||||
ZipArchive::DirectoryInfos _dirs;
|
||||
ZipArchive::DirectoryInfos64 _dirs64;
|
||||
Poco::UInt64 _offset;
|
||||
std::string _comment;
|
||||
Poco::UInt64 _offset;
|
||||
std::string _comment;
|
||||
|
||||
friend class Keep;
|
||||
friend class Rename;
|
||||
@ -127,6 +127,8 @@ private:
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
|
||||
|
||||
inline void Compress::setZipComment(const std::string& comment)
|
||||
{
|
||||
_comment = comment;
|
||||
|
@ -5,14 +5,14 @@
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: ZipArchive
|
||||
// Module: ZipArchive
|
||||
//
|
||||
// Definition of the ZipArchive class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
@ -73,9 +73,9 @@ private:
|
||||
ZipArchive(const FileHeaders& entries, const FileInfos& infos, const DirectoryInfos& dirs, const DirectoryInfos64& dirs64 );
|
||||
|
||||
private:
|
||||
FileHeaders _entries;
|
||||
FileHeaders _entries;
|
||||
/// Info generated by parsing the data block of the zip file
|
||||
FileInfos _infos;
|
||||
FileInfos _infos;
|
||||
/// Info generated by parsing the directory block of the zip file
|
||||
DirectoryInfos _disks;
|
||||
/// Stores directory info for all found disks
|
||||
|
@ -5,14 +5,14 @@
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: ZipArchiveInfo
|
||||
// Module: ZipArchiveInfo
|
||||
//
|
||||
// Definition of the ZipArchiveInfo class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
@ -113,12 +113,128 @@ private:
|
||||
FULLHEADER_SIZE = 22
|
||||
};
|
||||
|
||||
char _rawInfo[FULLHEADER_SIZE];
|
||||
char _rawInfo[FULLHEADER_SIZE];
|
||||
std::streamoff _startPos;
|
||||
std::string _comment;
|
||||
std::string _comment;
|
||||
};
|
||||
|
||||
|
||||
class Zip_API ZipArchiveInfo64
|
||||
/// A ZipArchiveInfo64 stores central directory info
|
||||
{
|
||||
public:
|
||||
static const char HEADER[ZipCommon::HEADER_SIZE];
|
||||
static const char LOCATOR_HEADER[ZipCommon::HEADER_SIZE];
|
||||
|
||||
ZipArchiveInfo64();
|
||||
/// Default constructor, everything set to zero or empty
|
||||
|
||||
ZipArchiveInfo64(std::istream& in, bool assumeHeaderRead);
|
||||
/// Creates the ZipArchiveInfo64 by parsing the input stream.
|
||||
/// If assumeHeaderRead is true we assume that the first 4 bytes were already read outside.
|
||||
|
||||
~ZipArchiveInfo64();
|
||||
/// Destroys the ZipArchiveInfo64.
|
||||
|
||||
void getVersionMadeBy(int& major, int& minor);
|
||||
/// The ZIP version used to create the file
|
||||
|
||||
void getRequiredVersion(int& major, int& minor);
|
||||
/// The minimum version required to extract the data
|
||||
|
||||
Poco::UInt32 getDiskNumber() const;
|
||||
/// Get the number of the disk where this header can be found
|
||||
|
||||
Poco::UInt32 getFirstDiskForDirectoryHeader() const;
|
||||
/// Returns the number of the disk that contains the start of the directory header
|
||||
|
||||
Poco::UInt64 getNumberOfEntries() const;
|
||||
/// Returns the number of entries on this disk
|
||||
|
||||
Poco::UInt64 getTotalNumberOfEntries() const;
|
||||
/// Returns the total number of entries on all disks
|
||||
|
||||
Poco::UInt64 getCentralDirectorySize() const;
|
||||
/// Returns the size of the central directory in bytes
|
||||
|
||||
std::streamoff getCentralDirectoryOffset() const;
|
||||
/// Returns the offset of the central directory from beginning of first disk
|
||||
|
||||
std::streamoff getHeaderOffset() const;
|
||||
/// Returns the offset of the header in relation to the begin of this disk
|
||||
|
||||
void setNumberOfEntries(Poco::UInt64 val);
|
||||
/// Sets the number of entries on this disk
|
||||
|
||||
void setTotalNumberOfEntries(Poco::UInt64 val);
|
||||
/// Sets the total number of entries on all disks
|
||||
|
||||
void setCentralDirectorySize(Poco::UInt64 val);
|
||||
/// Set the size of the central directory in bytes
|
||||
|
||||
void setCentralDirectoryOffset(Poco::UInt64 val);
|
||||
/// Returns the offset of the central directory from beginning of first disk
|
||||
|
||||
void setHeaderOffset(std::streamoff val);
|
||||
/// Sets the offset of the header in relation to the begin of this disk
|
||||
|
||||
void setTotalNumberOfDisks(Poco::UInt32 val);
|
||||
/// Sets the offset of the central directory from beginning of first disk
|
||||
|
||||
std::string createHeader() const;
|
||||
/// Creates a header
|
||||
|
||||
private:
|
||||
void parse(std::istream& inp, bool assumeHeaderRead);
|
||||
void setRequiredVersion(int major, int minor);
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
HEADER_POS = 0,
|
||||
RECORDSIZE_POS = HEADER_POS + ZipCommon::HEADER_SIZE,
|
||||
RECORDSIZE_SIZE = 8,
|
||||
VERSIONMADEBY_POS = RECORDSIZE_POS + RECORDSIZE_SIZE,
|
||||
VERSIONMADEBY_SIZE = 2,
|
||||
VERSION_NEEDED_POS = VERSIONMADEBY_POS + VERSIONMADEBY_SIZE,
|
||||
VERSION_NEEDED_SIZE = 2,
|
||||
NUMBEROFTHISDISK_POS = VERSION_NEEDED_POS + VERSION_NEEDED_SIZE,
|
||||
NUMBEROFTHISDISK_SIZE = 4,
|
||||
NUMBEROFCENTRALDIRDISK_POS = NUMBEROFTHISDISK_POS + NUMBEROFTHISDISK_SIZE,
|
||||
NUMBEROFCENTRALDIRDISK_SIZE = 4,
|
||||
NUMENTRIESTHISDISK_POS = NUMBEROFCENTRALDIRDISK_POS + NUMBEROFCENTRALDIRDISK_SIZE,
|
||||
NUMENTRIESTHISDISK_SIZE = 8,
|
||||
TOTALNUMENTRIES_POS = NUMENTRIESTHISDISK_POS + NUMENTRIESTHISDISK_SIZE,
|
||||
TOTALNUMENTRIES_SIZE = 8,
|
||||
CENTRALDIRSIZE_POS = TOTALNUMENTRIES_POS + TOTALNUMENTRIES_SIZE,
|
||||
CENTRALDIRSIZE_SIZE = 8,
|
||||
CENTRALDIRSTARTOFFSET_POS = CENTRALDIRSIZE_POS + CENTRALDIRSIZE_SIZE,
|
||||
CENTRALDIRSTARTOFFSET_SIZE = 8,
|
||||
FULL_HEADER_SIZE = 56,
|
||||
|
||||
LOCATOR_HEADER_POS = 0,
|
||||
NUMBEROFENDOFCENTRALDIRDISK_POS = LOCATOR_HEADER_POS + ZipCommon::HEADER_SIZE,
|
||||
NUMBEROFENDOFCENTRALDIRDISK_SIZE = 4,
|
||||
ENDOFCENTRALDIROFFSET_POS = NUMBEROFENDOFCENTRALDIRDISK_POS + NUMBEROFENDOFCENTRALDIRDISK_SIZE,
|
||||
ENDOFCENTRALDIROFFSET_SIZE = 8,
|
||||
TOTALNUMBEROFENDDISKS_POS = ENDOFCENTRALDIROFFSET_POS + ENDOFCENTRALDIROFFSET_SIZE,
|
||||
TOTALNUMBEROFENDDISKS_SIZE = 4,
|
||||
|
||||
FULL_LOCATOR_SIZE = 20
|
||||
};
|
||||
|
||||
char _rawInfo[FULL_HEADER_SIZE];
|
||||
std::string _extraField;
|
||||
char _locInfo[FULL_LOCATOR_SIZE];
|
||||
std::streamoff _startPos;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
|
||||
|
||||
inline Poco::UInt16 ZipArchiveInfo::getDiskNumber() const
|
||||
{
|
||||
return ZipUtil::get16BitValue(_rawInfo, NUMBEROFTHISDISK_POS);
|
||||
@ -196,119 +312,6 @@ inline void ZipArchiveInfo::setHeaderOffset(std::streamoff val)
|
||||
}
|
||||
|
||||
|
||||
|
||||
class Zip_API ZipArchiveInfo64
|
||||
/// A ZipArchiveInfo64 stores central directory info
|
||||
{
|
||||
public:
|
||||
static const char HEADER[ZipCommon::HEADER_SIZE];
|
||||
static const char LOCATOR_HEADER[ZipCommon::HEADER_SIZE];
|
||||
|
||||
ZipArchiveInfo64();
|
||||
/// Default constructor, everything set to zero or empty
|
||||
|
||||
ZipArchiveInfo64(std::istream& in, bool assumeHeaderRead);
|
||||
/// Creates the ZipArchiveInfo64 by parsing the input stream.
|
||||
/// If assumeHeaderRead is true we assume that the first 4 bytes were already read outside.
|
||||
|
||||
~ZipArchiveInfo64();
|
||||
/// Destroys the ZipArchiveInfo64.
|
||||
|
||||
void getVersionMadeBy(int& major, int& minor);
|
||||
/// The ZIP version used to create the file
|
||||
|
||||
void getRequiredVersion(int& major, int& minor);
|
||||
/// The minimum version required to extract the data
|
||||
|
||||
Poco::UInt32 getDiskNumber() const;
|
||||
/// Get the number of the disk where this header can be found
|
||||
|
||||
Poco::UInt32 getFirstDiskForDirectoryHeader() const;
|
||||
/// Returns the number of the disk that contains the start of the directory header
|
||||
|
||||
Poco::UInt64 getNumberOfEntries() const;
|
||||
/// Returns the number of entries on this disk
|
||||
|
||||
Poco::UInt64 getTotalNumberOfEntries() const;
|
||||
/// Returns the total number of entries on all disks
|
||||
|
||||
Poco::UInt64 getCentralDirectorySize() const;
|
||||
/// Returns the size of the central directory in bytes
|
||||
|
||||
std::streamoff getCentralDirectoryOffset() const;
|
||||
/// Returns the offset of the central directory from beginning of first disk
|
||||
|
||||
std::streamoff getHeaderOffset() const;
|
||||
/// Returns the offset of the header in relation to the begin of this disk
|
||||
|
||||
void setNumberOfEntries(Poco::UInt64 val);
|
||||
/// Sets the number of entries on this disk
|
||||
|
||||
void setTotalNumberOfEntries(Poco::UInt64 val);
|
||||
/// Sets the total number of entries on all disks
|
||||
|
||||
void setCentralDirectorySize(Poco::UInt64 val);
|
||||
/// Set the size of the central directory in bytes
|
||||
|
||||
void setCentralDirectoryOffset(Poco::UInt64 val);
|
||||
/// Returns the offset of the central directory from beginning of first disk
|
||||
|
||||
void setHeaderOffset(std::streamoff val);
|
||||
/// Sets the offset of the header in relation to the begin of this disk
|
||||
|
||||
void setTotalNumberOfDisks(Poco::UInt32 val);
|
||||
/// Sets the offset of the central directory from beginning of first disk
|
||||
|
||||
std::string createHeader() const;
|
||||
/// Creates a header
|
||||
|
||||
private:
|
||||
void parse(std::istream& inp, bool assumeHeaderRead);
|
||||
|
||||
void setRequiredVersion(int major, int minor);
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
HEADER_POS = 0,
|
||||
RECORDSIZE_POS = HEADER_POS + ZipCommon::HEADER_SIZE,
|
||||
RECORDSIZE_SIZE = 8,
|
||||
VERSIONMADEBY_POS = RECORDSIZE_POS + RECORDSIZE_SIZE,
|
||||
VERSIONMADEBY_SIZE = 2,
|
||||
VERSION_NEEDED_POS = VERSIONMADEBY_POS + VERSIONMADEBY_SIZE,
|
||||
VERSION_NEEDED_SIZE = 2,
|
||||
NUMBEROFTHISDISK_POS = VERSION_NEEDED_POS + VERSION_NEEDED_SIZE,
|
||||
NUMBEROFTHISDISK_SIZE = 4,
|
||||
NUMBEROFCENTRALDIRDISK_POS = NUMBEROFTHISDISK_POS + NUMBEROFTHISDISK_SIZE,
|
||||
NUMBEROFCENTRALDIRDISK_SIZE = 4,
|
||||
NUMENTRIESTHISDISK_POS = NUMBEROFCENTRALDIRDISK_POS + NUMBEROFCENTRALDIRDISK_SIZE,
|
||||
NUMENTRIESTHISDISK_SIZE = 8,
|
||||
TOTALNUMENTRIES_POS = NUMENTRIESTHISDISK_POS + NUMENTRIESTHISDISK_SIZE,
|
||||
TOTALNUMENTRIES_SIZE = 8,
|
||||
CENTRALDIRSIZE_POS = TOTALNUMENTRIES_POS + TOTALNUMENTRIES_SIZE,
|
||||
CENTRALDIRSIZE_SIZE = 8,
|
||||
CENTRALDIRSTARTOFFSET_POS = CENTRALDIRSIZE_POS + CENTRALDIRSIZE_SIZE,
|
||||
CENTRALDIRSTARTOFFSET_SIZE = 8,
|
||||
FULL_HEADER_SIZE = 56,
|
||||
|
||||
LOCATOR_HEADER_POS = 0,
|
||||
NUMBEROFENDOFCENTRALDIRDISK_POS = LOCATOR_HEADER_POS + ZipCommon::HEADER_SIZE,
|
||||
NUMBEROFENDOFCENTRALDIRDISK_SIZE = 4,
|
||||
ENDOFCENTRALDIROFFSET_POS = NUMBEROFENDOFCENTRALDIRDISK_POS + NUMBEROFENDOFCENTRALDIRDISK_SIZE,
|
||||
ENDOFCENTRALDIROFFSET_SIZE = 8,
|
||||
TOTALNUMBEROFENDDISKS_POS = ENDOFCENTRALDIROFFSET_POS + ENDOFCENTRALDIROFFSET_SIZE,
|
||||
TOTALNUMBEROFENDDISKS_SIZE = 4,
|
||||
|
||||
FULL_LOCATOR_SIZE = 20
|
||||
};
|
||||
|
||||
char _rawInfo[FULL_HEADER_SIZE];
|
||||
std::string _extraField;
|
||||
char _locInfo[FULL_LOCATOR_SIZE];
|
||||
std::streamoff _startPos;
|
||||
};
|
||||
|
||||
|
||||
inline Poco::UInt32 ZipArchiveInfo64::getDiskNumber() const
|
||||
{
|
||||
return ZipUtil::get32BitValue(_rawInfo, NUMBEROFTHISDISK_POS);
|
||||
@ -344,11 +347,13 @@ inline std::streamoff ZipArchiveInfo64::getCentralDirectoryOffset() const
|
||||
return _startPos;
|
||||
}
|
||||
|
||||
|
||||
inline std::streamoff ZipArchiveInfo64::getHeaderOffset() const
|
||||
{
|
||||
return _startPos;
|
||||
}
|
||||
|
||||
|
||||
inline void ZipArchiveInfo64::setRequiredVersion(int major, int minor)
|
||||
{
|
||||
poco_assert (minor < 10);
|
||||
@ -358,6 +363,7 @@ inline void ZipArchiveInfo64::setRequiredVersion(int major, int minor)
|
||||
_rawInfo[VERSION_NEEDED_POS] = static_cast<char>(val);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipArchiveInfo64::setNumberOfEntries(Poco::UInt64 val)
|
||||
{
|
||||
ZipUtil::set64BitValue(val, _rawInfo, NUMENTRIESTHISDISK_POS);
|
||||
@ -369,27 +375,32 @@ inline void ZipArchiveInfo64::setTotalNumberOfEntries(Poco::UInt64 val)
|
||||
ZipUtil::set64BitValue(val, _rawInfo, TOTALNUMENTRIES_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipArchiveInfo64::setCentralDirectorySize(Poco::UInt64 val)
|
||||
{
|
||||
ZipUtil::set64BitValue(val, _rawInfo, CENTRALDIRSIZE_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipArchiveInfo64::setCentralDirectoryOffset(Poco::UInt64 val)
|
||||
{
|
||||
ZipUtil::set64BitValue(val, _rawInfo, CENTRALDIRSTARTOFFSET_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipArchiveInfo64::setHeaderOffset(std::streamoff val)
|
||||
{
|
||||
_startPos = val;
|
||||
_startPos = val;
|
||||
ZipUtil::set64BitValue(val, _locInfo, ENDOFCENTRALDIROFFSET_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipArchiveInfo64::setTotalNumberOfDisks(Poco::UInt32 val)
|
||||
{
|
||||
ZipUtil::set32BitValue(val, _locInfo, TOTALNUMBEROFENDDISKS_POS);
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
||||
|
||||
|
@ -5,14 +5,14 @@
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: ZipCommon
|
||||
// Module: ZipCommon
|
||||
//
|
||||
// Definition of the ZipCommon class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
@ -34,11 +34,11 @@ public:
|
||||
enum
|
||||
{
|
||||
HEADER_SIZE = 4,
|
||||
};
|
||||
};
|
||||
|
||||
static const Poco::UInt16 ZIP64_EXTRA_ID = 0x1; // Extra data id tag for Zip64 data (in extension for ZipLocalFileHeader and ZipFileInfo)
|
||||
static const Poco::UInt16 ZIP64_MAGIC_SHORT = 0xFFFF;
|
||||
static const Poco::UInt32 ZIP64_MAGIC = 0xFFFFFFFF;
|
||||
static const Poco::UInt16 ZIP64_EXTRA_ID = 0x1; // Extra data id tag for Zip64 data (in extension for ZipLocalFileHeader and ZipFileInfo)
|
||||
static const Poco::UInt16 ZIP64_MAGIC_SHORT = 0xFFFF;
|
||||
static const Poco::UInt32 ZIP64_MAGIC = 0xFFFFFFFF;
|
||||
|
||||
enum CompressionMethod
|
||||
{
|
||||
@ -59,15 +59,15 @@ public:
|
||||
|
||||
enum CompressionLevel
|
||||
{
|
||||
CL_NORMAL = 0,
|
||||
CL_MAXIMUM = 1,
|
||||
CL_FAST = 2,
|
||||
CL_NORMAL = 0,
|
||||
CL_MAXIMUM = 1,
|
||||
CL_FAST = 2,
|
||||
CL_SUPERFAST = 3
|
||||
};
|
||||
|
||||
enum HostSystem
|
||||
{
|
||||
HS_FAT = 0, // + PKZIPW 2.50 VFAT, NTFS
|
||||
HS_FAT = 0, // + PKZIPW 2.50 VFAT, NTFS
|
||||
HS_AMIGA = 1,
|
||||
HS_VMS = 2,
|
||||
HS_UNIX = 3,
|
||||
|
@ -5,14 +5,14 @@
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: ZipDataInfo
|
||||
// Module: ZipDataInfo
|
||||
//
|
||||
// Definition of the ZipDataInfo class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
@ -80,6 +80,62 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class Zip_API ZipDataInfo64
|
||||
/// A ZipDataInfo64 stores a Zip data descriptor for a Zip64 file
|
||||
{
|
||||
public:
|
||||
static const char HEADER[ZipCommon::HEADER_SIZE];
|
||||
|
||||
ZipDataInfo64();
|
||||
/// Creates a header with all fields (except the header field) set to 0
|
||||
|
||||
ZipDataInfo64(std::istream& in, bool assumeHeaderRead);
|
||||
/// Creates the ZipDataInfo64.
|
||||
|
||||
~ZipDataInfo64();
|
||||
/// Destroys the ZipDataInfo64.
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
Poco::UInt32 getCRC32() const;
|
||||
|
||||
void setCRC32(Poco::UInt32 crc);
|
||||
|
||||
Poco::UInt64 getCompressedSize() const;
|
||||
|
||||
void setCompressedSize(Poco::UInt64 size);
|
||||
|
||||
Poco::UInt64 getUncompressedSize() const;
|
||||
|
||||
void setUncompressedSize(Poco::UInt64 size);
|
||||
|
||||
static Poco::UInt32 getFullHeaderSize();
|
||||
|
||||
const char* getRawHeader() const;
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
HEADER_POS = 0,
|
||||
CRC32_POS = HEADER_POS + ZipCommon::HEADER_SIZE,
|
||||
CRC32_SIZE = 4,
|
||||
COMPRESSED_POS = CRC32_POS + CRC32_SIZE,
|
||||
COMPRESSED_SIZE = 8,
|
||||
UNCOMPRESSED_POS = COMPRESSED_POS + COMPRESSED_SIZE,
|
||||
UNCOMPRESSED_SIZE = 8,
|
||||
FULLHEADER_SIZE = UNCOMPRESSED_POS + UNCOMPRESSED_SIZE
|
||||
};
|
||||
|
||||
char _rawInfo[FULLHEADER_SIZE];
|
||||
bool _valid;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
|
||||
|
||||
inline const char* ZipDataInfo::getRawHeader() const
|
||||
{
|
||||
return _rawInfo;
|
||||
@ -134,57 +190,6 @@ inline Poco::UInt32 ZipDataInfo::getFullHeaderSize()
|
||||
}
|
||||
|
||||
|
||||
class Zip_API ZipDataInfo64
|
||||
/// A ZipDataInfo64 stores a Zip data descriptor for a Zip64 file
|
||||
{
|
||||
public:
|
||||
static const char HEADER[ZipCommon::HEADER_SIZE];
|
||||
|
||||
ZipDataInfo64();
|
||||
/// Creates a header with all fields (except the header field) set to 0
|
||||
|
||||
ZipDataInfo64(std::istream& in, bool assumeHeaderRead);
|
||||
/// Creates the ZipDataInfo64.
|
||||
|
||||
~ZipDataInfo64();
|
||||
/// Destroys the ZipDataInfo64.
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
Poco::UInt32 getCRC32() const;
|
||||
|
||||
void setCRC32(Poco::UInt32 crc);
|
||||
|
||||
Poco::UInt64 getCompressedSize() const;
|
||||
|
||||
void setCompressedSize(Poco::UInt64 size);
|
||||
|
||||
Poco::UInt64 getUncompressedSize() const;
|
||||
|
||||
void setUncompressedSize(Poco::UInt64 size);
|
||||
|
||||
static Poco::UInt32 getFullHeaderSize();
|
||||
|
||||
const char* getRawHeader() const;
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
HEADER_POS = 0,
|
||||
CRC32_POS = HEADER_POS + ZipCommon::HEADER_SIZE,
|
||||
CRC32_SIZE = 4,
|
||||
COMPRESSED_POS = CRC32_POS + CRC32_SIZE,
|
||||
COMPRESSED_SIZE = 8,
|
||||
UNCOMPRESSED_POS = COMPRESSED_POS + COMPRESSED_SIZE,
|
||||
UNCOMPRESSED_SIZE = 8,
|
||||
FULLHEADER_SIZE = UNCOMPRESSED_POS + UNCOMPRESSED_SIZE
|
||||
};
|
||||
|
||||
char _rawInfo[FULLHEADER_SIZE];
|
||||
bool _valid;
|
||||
};
|
||||
|
||||
|
||||
inline const char* ZipDataInfo64::getRawHeader() const
|
||||
{
|
||||
return _rawInfo;
|
||||
@ -238,6 +243,8 @@ inline Poco::UInt32 ZipDataInfo64::getFullHeaderSize()
|
||||
return FULLHEADER_SIZE;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
||||
|
||||
#endif // Zip_ZipDataInfo_INCLUDED
|
||||
|
@ -5,14 +5,14 @@
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: ZipFileInfo
|
||||
// Module: ZipFileInfo
|
||||
//
|
||||
// Definition of the ZipFileInfo class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
@ -96,15 +96,15 @@ public:
|
||||
|
||||
void setOffset(Poco::UInt64 val);
|
||||
|
||||
bool needsZip64() const;
|
||||
bool needsZip64() const;
|
||||
|
||||
void setZip64Data();
|
||||
void setZip64Data();
|
||||
|
||||
private:
|
||||
|
||||
void setCRC(Poco::UInt32 val);
|
||||
|
||||
void setCompressedSize(Poco::UInt64 val);
|
||||
void setCompressedSize(Poco::UInt64 val);
|
||||
|
||||
void setUncompressedSize(Poco::UInt64 val);
|
||||
|
||||
@ -186,15 +186,15 @@ private:
|
||||
RELATIVEOFFSETLOCALHEADER_SIZE = 4,
|
||||
FULLHEADER_SIZE = 46,
|
||||
|
||||
EXTRA_DATA_TAG_SIZE = 2,
|
||||
EXTRA_DATA_TAG_POS = 0,
|
||||
EXTRA_DATA_SIZE_SIZE = 2,
|
||||
EXTRA_DATA_SIZE_POS = EXTRA_DATA_TAG_POS + EXTRA_DATA_TAG_SIZE,
|
||||
EXTRA_DATA_POS = EXTRA_DATA_SIZE_POS + EXTRA_DATA_SIZE_SIZE,
|
||||
EXTRA_DATA_UNCOMPRESSED_SIZE_SIZE = 8,
|
||||
EXTRA_DATA_COMPRESSED_SIZE_SIZE = 8,
|
||||
EXTRA_DATA_OFFSET_SIZE = 8,
|
||||
FULLEXTRA_DATA_SIZE = 28
|
||||
EXTRA_DATA_TAG_SIZE = 2,
|
||||
EXTRA_DATA_TAG_POS = 0,
|
||||
EXTRA_DATA_SIZE_SIZE = 2,
|
||||
EXTRA_DATA_SIZE_POS = EXTRA_DATA_TAG_POS + EXTRA_DATA_TAG_SIZE,
|
||||
EXTRA_DATA_POS = EXTRA_DATA_SIZE_POS + EXTRA_DATA_SIZE_SIZE,
|
||||
EXTRA_DATA_UNCOMPRESSED_SIZE_SIZE = 8,
|
||||
EXTRA_DATA_COMPRESSED_SIZE_SIZE = 8,
|
||||
EXTRA_DATA_OFFSET_SIZE = 8,
|
||||
FULLEXTRA_DATA_SIZE = 28
|
||||
};
|
||||
|
||||
enum
|
||||
@ -203,15 +203,15 @@ private:
|
||||
DEFAULT_UNIX_DIR_MODE = 0755
|
||||
};
|
||||
|
||||
char _rawInfo[FULLHEADER_SIZE];
|
||||
char _rawInfo[FULLHEADER_SIZE];
|
||||
Poco::UInt32 _crc32;
|
||||
Poco::UInt64 _compressedSize;
|
||||
Poco::UInt64 _uncompressedSize;
|
||||
Poco::UInt64 _localHeaderOffset;
|
||||
std::string _fileName;
|
||||
std::string _fileName;
|
||||
Poco::DateTime _lastModifiedAt;
|
||||
std::string _extraField;
|
||||
std::string _fileComment;
|
||||
std::string _extraField;
|
||||
std::string _fileComment;
|
||||
};
|
||||
|
||||
|
||||
@ -263,11 +263,13 @@ inline const Poco::DateTime& ZipFileInfo::lastModifiedAt() const
|
||||
return _lastModifiedAt;
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt64 ZipFileInfo::getOffset() const
|
||||
{
|
||||
return _localHeaderOffset;
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 ZipFileInfo::getCRC() const
|
||||
{
|
||||
return _crc32;
|
||||
@ -384,31 +386,40 @@ inline Poco::UInt32 ZipFileInfo::getHeaderSize() const
|
||||
return FULLHEADER_SIZE + getFileNameLength() + getExtraFieldLength() + getFileCommentLength();
|
||||
}
|
||||
|
||||
inline bool ZipFileInfo::needsZip64() const {
|
||||
return _localHeaderOffset >= ZipCommon::ZIP64_MAGIC || _compressedSize >= ZipCommon::ZIP64_MAGIC || _uncompressedSize >= ZipCommon::ZIP64_MAGIC;
|
||||
|
||||
inline bool ZipFileInfo::needsZip64() const
|
||||
{
|
||||
return _localHeaderOffset >= ZipCommon::ZIP64_MAGIC || _compressedSize >= ZipCommon::ZIP64_MAGIC || _uncompressedSize >= ZipCommon::ZIP64_MAGIC;
|
||||
}
|
||||
|
||||
inline void ZipFileInfo::setZip64Data() {
|
||||
if(needsZip64()) {
|
||||
setRequiredVersion(4, 5);
|
||||
char data[FULLEXTRA_DATA_SIZE];
|
||||
ZipUtil::set16BitValue(ZipCommon::ZIP64_EXTRA_ID, data, EXTRA_DATA_TAG_POS);
|
||||
Poco::UInt16 pos = EXTRA_DATA_POS;
|
||||
if(_uncompressedSize >= ZipCommon::ZIP64_MAGIC) {
|
||||
ZipUtil::set64BitValue(_uncompressedSize, data, pos); pos += 8;
|
||||
}
|
||||
if(_compressedSize >= ZipCommon::ZIP64_MAGIC) {
|
||||
ZipUtil::set64BitValue(_compressedSize, data, pos); pos += 8;
|
||||
}
|
||||
if(_localHeaderOffset >= ZipCommon::ZIP64_MAGIC) {
|
||||
ZipUtil::set64BitValue(_localHeaderOffset, data, pos); pos += 8;
|
||||
}
|
||||
ZipUtil::set16BitValue(pos - EXTRA_DATA_POS, data, EXTRA_DATA_SIZE_POS);
|
||||
_extraField = std::string(data, pos);
|
||||
ZipUtil::set16BitValue(pos, _rawInfo, EXTRAFIELD_LENGTH_POS);
|
||||
}
|
||||
|
||||
inline void ZipFileInfo::setZip64Data()
|
||||
{
|
||||
if (needsZip64())
|
||||
{
|
||||
setRequiredVersion(4, 5);
|
||||
char data[FULLEXTRA_DATA_SIZE];
|
||||
ZipUtil::set16BitValue(ZipCommon::ZIP64_EXTRA_ID, data, EXTRA_DATA_TAG_POS);
|
||||
Poco::UInt16 pos = EXTRA_DATA_POS;
|
||||
if (_uncompressedSize >= ZipCommon::ZIP64_MAGIC)
|
||||
{
|
||||
ZipUtil::set64BitValue(_uncompressedSize, data, pos); pos += 8;
|
||||
}
|
||||
if (_compressedSize >= ZipCommon::ZIP64_MAGIC)
|
||||
{
|
||||
ZipUtil::set64BitValue(_compressedSize, data, pos); pos += 8;
|
||||
}
|
||||
if (_localHeaderOffset >= ZipCommon::ZIP64_MAGIC)
|
||||
{
|
||||
ZipUtil::set64BitValue(_localHeaderOffset, data, pos); pos += 8;
|
||||
}
|
||||
ZipUtil::set16BitValue(pos - EXTRA_DATA_POS, data, EXTRA_DATA_SIZE_POS);
|
||||
_extraField = std::string(data, pos);
|
||||
ZipUtil::set16BitValue(pos, _rawInfo, EXTRAFIELD_LENGTH_POS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline void ZipFileInfo::setCRC(Poco::UInt32 val)
|
||||
{
|
||||
_crc32 = val;
|
||||
@ -418,7 +429,7 @@ inline void ZipFileInfo::setCRC(Poco::UInt32 val)
|
||||
|
||||
inline void ZipFileInfo::setOffset(Poco::UInt64 val)
|
||||
{
|
||||
_localHeaderOffset = val;
|
||||
_localHeaderOffset = val;
|
||||
ZipUtil::set32BitValue(val >= ZipCommon::ZIP64_MAGIC ? ZipCommon::ZIP64_MAGIC : static_cast<Poco::UInt32>(val), _rawInfo, RELATIVEOFFSETLOCALHEADER_POS);
|
||||
}
|
||||
|
||||
|
@ -5,14 +5,14 @@
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: ZipLocalFileHeader
|
||||
// Module: ZipLocalFileHeader
|
||||
//
|
||||
// Definition of the ZipLocalFileHeader class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
@ -83,7 +83,7 @@ public:
|
||||
ZipCommon::CompressionMethod getCompressionMethod() const;
|
||||
|
||||
ZipCommon::CompressionLevel getCompressionLevel() const;
|
||||
/// Returns the compression level used. Only valid when the compression method is CM_DEFLATE
|
||||
/// Returns the compression level used. Only valid when the compression method is CM_DEFLATE
|
||||
|
||||
bool isEncrypted() const;
|
||||
|
||||
@ -119,9 +119,9 @@ public:
|
||||
|
||||
void setFileName(const std::string& fileName, bool isDirectory);
|
||||
|
||||
bool needsZip64() const;
|
||||
bool needsZip64() const;
|
||||
|
||||
void setZip64Data();
|
||||
void setZip64Data();
|
||||
|
||||
std::string createHeader() const;
|
||||
/// Creates a header
|
||||
@ -185,23 +185,23 @@ private:
|
||||
EXTRA_FIELD_POS = FILE_LENGTH_POS + FILE_LENGTH_SIZE,
|
||||
FULLHEADER_SIZE = 30,
|
||||
|
||||
EXTRA_DATA_TAG_SIZE = 2,
|
||||
EXTRA_DATA_TAG_POS = 0,
|
||||
EXTRA_DATA_SIZE_SIZE = 2,
|
||||
EXTRA_DATA_SIZE_POS = EXTRA_DATA_TAG_POS + EXTRA_DATA_TAG_SIZE,
|
||||
EXTRA_DATA_POS = EXTRA_DATA_SIZE_POS + EXTRA_DATA_SIZE_SIZE,
|
||||
EXTRA_DATA_UNCOMPRESSED_SIZE_SIZE = 8,
|
||||
EXTRA_DATA_COMPRESSED_SIZE_SIZE = 8,
|
||||
FULLEXTRA_DATA_SIZE = 20
|
||||
EXTRA_DATA_TAG_SIZE = 2,
|
||||
EXTRA_DATA_TAG_POS = 0,
|
||||
EXTRA_DATA_SIZE_SIZE = 2,
|
||||
EXTRA_DATA_SIZE_POS = EXTRA_DATA_TAG_POS + EXTRA_DATA_TAG_SIZE,
|
||||
EXTRA_DATA_POS = EXTRA_DATA_SIZE_POS + EXTRA_DATA_SIZE_SIZE,
|
||||
EXTRA_DATA_UNCOMPRESSED_SIZE_SIZE = 8,
|
||||
EXTRA_DATA_COMPRESSED_SIZE_SIZE = 8,
|
||||
FULLEXTRA_DATA_SIZE = 20
|
||||
};
|
||||
|
||||
bool _forceZip64;
|
||||
char _rawHeader[FULLHEADER_SIZE];
|
||||
bool _forceZip64;
|
||||
char _rawHeader[FULLHEADER_SIZE];
|
||||
std::streamoff _startPos;
|
||||
std::streamoff _endPos;
|
||||
std::string _fileName;
|
||||
std::string _fileName;
|
||||
Poco::DateTime _lastModifiedAt;
|
||||
std::string _extraField;
|
||||
std::string _extraField;
|
||||
Poco::UInt32 _crc32;
|
||||
Poco::UInt64 _compressedSize;
|
||||
Poco::UInt64 _uncompressedSize;
|
||||
@ -250,24 +250,29 @@ inline void ZipLocalFileHeader::getRequiredVersion(int& major, int& minor)
|
||||
minor = getMinorVersionNumber();
|
||||
}
|
||||
|
||||
inline bool ZipLocalFileHeader::needsZip64() const {
|
||||
return _forceZip64 || _startPos >= ZipCommon::ZIP64_MAGIC || _compressedSize >= ZipCommon::ZIP64_MAGIC || _uncompressedSize >= ZipCommon::ZIP64_MAGIC;
|
||||
|
||||
inline bool ZipLocalFileHeader::needsZip64() const
|
||||
{
|
||||
return _forceZip64 || _startPos >= ZipCommon::ZIP64_MAGIC || _compressedSize >= ZipCommon::ZIP64_MAGIC || _uncompressedSize >= ZipCommon::ZIP64_MAGIC;
|
||||
}
|
||||
|
||||
inline void ZipLocalFileHeader::setZip64Data() {
|
||||
setRequiredVersion(4, 5);
|
||||
char data[FULLEXTRA_DATA_SIZE];
|
||||
ZipUtil::set16BitValue(ZipCommon::ZIP64_EXTRA_ID, data, EXTRA_DATA_TAG_POS);
|
||||
Poco::UInt16 pos = EXTRA_DATA_POS;
|
||||
ZipUtil::set64BitValue(_uncompressedSize, data, pos); pos += 8;
|
||||
|
||||
inline void ZipLocalFileHeader::setZip64Data()
|
||||
{
|
||||
setRequiredVersion(4, 5);
|
||||
char data[FULLEXTRA_DATA_SIZE];
|
||||
ZipUtil::set16BitValue(ZipCommon::ZIP64_EXTRA_ID, data, EXTRA_DATA_TAG_POS);
|
||||
Poco::UInt16 pos = EXTRA_DATA_POS;
|
||||
ZipUtil::set64BitValue(_uncompressedSize, data, pos); pos += 8;
|
||||
ZipUtil::set32BitValue(ZipCommon::ZIP64_MAGIC, _rawHeader, UNCOMPRESSED_SIZE_POS);
|
||||
ZipUtil::set64BitValue(_compressedSize, data, pos); pos += 8;
|
||||
ZipUtil::set64BitValue(_compressedSize, data, pos); pos += 8;
|
||||
ZipUtil::set32BitValue(ZipCommon::ZIP64_MAGIC, _rawHeader, COMPRESSED_SIZE_POS);
|
||||
ZipUtil::set16BitValue(pos - EXTRA_DATA_POS, data, EXTRA_DATA_SIZE_POS);
|
||||
_extraField = std::string(data, pos);
|
||||
ZipUtil::set16BitValue(pos, _rawHeader, EXTRA_FIELD_POS);
|
||||
ZipUtil::set16BitValue(pos - EXTRA_DATA_POS, data, EXTRA_DATA_SIZE_POS);
|
||||
_extraField = std::string(data, pos);
|
||||
ZipUtil::set16BitValue(pos, _rawHeader, EXTRA_FIELD_POS);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipLocalFileHeader::setRequiredVersion(int major, int minor)
|
||||
{
|
||||
poco_assert (minor < 10);
|
||||
|
@ -5,14 +5,14 @@
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: ZipStream
|
||||
// Module: ZipStream
|
||||
//
|
||||
// Definition of the ZipStream class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
@ -71,13 +71,13 @@ private:
|
||||
typedef Poco::SharedPtr<std::ostream> PtrOStream;
|
||||
std::istream* _pIstr;
|
||||
std::ostream* _pOstr;
|
||||
PtrIStream _ptrBuf;
|
||||
PtrOStream _ptrOBuf;
|
||||
PtrIStream _ptrHelper;
|
||||
PtrIStream _ptrBuf;
|
||||
PtrOStream _ptrOBuf;
|
||||
PtrIStream _ptrHelper;
|
||||
Poco::SharedPtr<PartialOutputStream> _ptrOHelper;
|
||||
Poco::Checksum _crc32;
|
||||
Poco::UInt32 _expectedCrc32;
|
||||
bool _checkCRC;
|
||||
bool _checkCRC;
|
||||
/// Note: we do not check crc if we decompress a streaming zip file and the crc is stored in the directory header
|
||||
Poco::UInt64 _bytesWritten;
|
||||
ZipLocalFileHeader* _pHeader;
|
||||
|
@ -5,14 +5,14 @@
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: ZipUtil
|
||||
// Module: ZipUtil
|
||||
//
|
||||
// Definition of the ZipUtil class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
@ -41,7 +41,7 @@ public:
|
||||
|
||||
static Poco::UInt64 get64BitValue(const char* pVal, const Poco::UInt32 pos);
|
||||
|
||||
static void set16BitValue(const Poco::UInt16 val, char* pVal, const Poco::UInt32 pos);
|
||||
static void set16BitValue(const Poco::UInt16 val, char* pVal, const Poco::UInt32 pos);
|
||||
|
||||
static void set32BitValue(const Poco::UInt32 val, char* pVal, const Poco::UInt32 pos);
|
||||
|
||||
@ -81,13 +81,15 @@ inline Poco::UInt32 ZipUtil::get32BitValue(const char* pVal, const Poco::UInt32
|
||||
(static_cast<Poco::UInt32>((unsigned char)pVal[pos+2]) << 16) + (static_cast<Poco::UInt32>((unsigned char)pVal[pos+3]) << 24);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt64 ZipUtil::get64BitValue(const char* pVal, const Poco::UInt32 pos)
|
||||
{
|
||||
Poco::UInt64 val = ZipUtil::get32BitValue(pVal, pos+4);
|
||||
val = (val << 32) | ZipUtil::get32BitValue(pVal, pos);
|
||||
return val;
|
||||
val = (val << 32) | ZipUtil::get32BitValue(pVal, pos);
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
inline void ZipUtil::set16BitValue(const Poco::UInt16 val, char* pVal, const Poco::UInt32 pos)
|
||||
{
|
||||
pVal[pos] = static_cast<char>(val);
|
||||
@ -103,6 +105,7 @@ inline void ZipUtil::set32BitValue(const Poco::UInt32 val, char* pVal, const Poc
|
||||
pVal[pos+3] = static_cast<char>(val>>24);
|
||||
}
|
||||
|
||||
|
||||
inline void ZipUtil::set64BitValue(const Poco::UInt64 val, char* pVal, const Poco::UInt32 pos)
|
||||
{
|
||||
pVal[pos] = static_cast<char>(val);
|
||||
@ -115,6 +118,7 @@ inline void ZipUtil::set64BitValue(const Poco::UInt64 val, char* pVal, const Poc
|
||||
pVal[pos+7] = static_cast<char>(val>>56);
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
||||
|
||||
|
@ -5,12 +5,12 @@
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: Compress
|
||||
// Module: Compress
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
@ -33,7 +33,7 @@ namespace Zip {
|
||||
Compress::Compress(std::ostream& out, bool seekableOut, bool forceZip64):
|
||||
_out(out),
|
||||
_seekableOut(seekableOut),
|
||||
_forceZip64(forceZip64),
|
||||
_forceZip64(forceZip64),
|
||||
_files(),
|
||||
_infos(),
|
||||
_dirs(),
|
||||
@ -73,15 +73,15 @@ void Compress::addEntry(std::istream& in, const Poco::DateTime& lastModifiedAt,
|
||||
|
||||
ZipOutputStream zipOut(_out, hdr, _seekableOut);
|
||||
Poco::StreamCopier::copyStream(in, zipOut);
|
||||
Poco::UInt64 extraDataSize;
|
||||
Poco::UInt64 extraDataSize;
|
||||
zipOut.close(extraDataSize);
|
||||
_offset = hdr.getEndPos();
|
||||
_offset += extraDataSize;
|
||||
_offset += extraDataSize;
|
||||
_files.insert(std::make_pair(fileName.toString(Poco::Path::PATH_UNIX), hdr));
|
||||
poco_assert (_out);
|
||||
ZipFileInfo nfo(hdr);
|
||||
nfo.setOffset(localHeaderOffset);
|
||||
nfo.setZip64Data();
|
||||
nfo.setZip64Data();
|
||||
_infos.insert(std::make_pair(fileName.toString(Poco::Path::PATH_UNIX), nfo));
|
||||
EDone.notify(this, hdr);
|
||||
}
|
||||
@ -100,8 +100,8 @@ void Compress::addFileRaw(std::istream& in, const ZipLocalFileHeader& h, const P
|
||||
ZipLocalFileHeader hdr(h);
|
||||
hdr.setFileName(fn, h.isDirectory());
|
||||
hdr.setStartPos(localHeaderOffset);
|
||||
if(hdr.needsZip64())
|
||||
hdr.setZip64Data();
|
||||
if(hdr.needsZip64())
|
||||
hdr.setZip64Data();
|
||||
//bypass zipoutputstream
|
||||
//write the header directly
|
||||
std::string header = hdr.createHeader();
|
||||
@ -135,30 +135,36 @@ void Compress::addFileRaw(std::istream& in, const ZipLocalFileHeader& h, const P
|
||||
hdr.setStartPos(localHeaderOffset); // This resets EndPos now that compressed Size is known
|
||||
_offset = hdr.getEndPos();
|
||||
//write optional block afterwards
|
||||
if (hdr.searchCRCAndSizesAfterData()) {
|
||||
if(hdr.needsZip64()) {
|
||||
ZipDataInfo64 info(in, false);
|
||||
_out.write(info.getRawHeader(), static_cast<std::streamsize>(info.getFullHeaderSize()));
|
||||
_offset += ZipDataInfo::getFullHeaderSize();
|
||||
} else {
|
||||
ZipDataInfo info(in, false);
|
||||
_out.write(info.getRawHeader(), static_cast<std::streamsize>(info.getFullHeaderSize()));
|
||||
_offset += ZipDataInfo::getFullHeaderSize();
|
||||
}
|
||||
} else {
|
||||
if(hdr.hasExtraField()) // Update sizes in header extension.
|
||||
hdr.setZip64Data();
|
||||
_out.seekp(hdr.getStartPos(), std::ios_base::beg);
|
||||
std::string header = hdr.createHeader();
|
||||
if (hdr.searchCRCAndSizesAfterData())
|
||||
{
|
||||
if (hdr.needsZip64())
|
||||
{
|
||||
ZipDataInfo64 info(in, false);
|
||||
_out.write(info.getRawHeader(), static_cast<std::streamsize>(info.getFullHeaderSize()));
|
||||
_offset += ZipDataInfo::getFullHeaderSize();
|
||||
}
|
||||
else
|
||||
{
|
||||
ZipDataInfo info(in, false);
|
||||
_out.write(info.getRawHeader(), static_cast<std::streamsize>(info.getFullHeaderSize()));
|
||||
_offset += ZipDataInfo::getFullHeaderSize();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(hdr.hasExtraField()) // Update sizes in header extension.
|
||||
hdr.setZip64Data();
|
||||
_out.seekp(hdr.getStartPos(), std::ios_base::beg);
|
||||
std::string header = hdr.createHeader();
|
||||
_out.write(header.c_str(), static_cast<std::streamsize>(header.size()));
|
||||
_out.seekp(0, std::ios_base::end);
|
||||
}
|
||||
_out.seekp(0, std::ios_base::end);
|
||||
}
|
||||
|
||||
_files.insert(std::make_pair(fileName.toString(Poco::Path::PATH_UNIX), hdr));
|
||||
poco_assert (_out);
|
||||
ZipFileInfo nfo(hdr);
|
||||
nfo.setOffset(localHeaderOffset);
|
||||
nfo.setZip64Data();
|
||||
nfo.setZip64Data();
|
||||
_infos.insert(std::make_pair(fileName.toString(Poco::Path::PATH_UNIX), nfo));
|
||||
EDone.notify(this, hdr);
|
||||
}
|
||||
@ -216,7 +222,7 @@ void Compress::addDirectory(const Poco::Path& entryName, const Poco::DateTime& l
|
||||
ZipLocalFileHeader hdr(entryName, lastModifiedAt, cm, cl);
|
||||
hdr.setStartPos(localHeaderOffset);
|
||||
ZipOutputStream zipOut(_out, hdr, _seekableOut);
|
||||
Poco::UInt64 extraDataSize;
|
||||
Poco::UInt64 extraDataSize;
|
||||
zipOut.close(extraDataSize);
|
||||
hdr.setStartPos(localHeaderOffset); // reset again now that compressed Size is known
|
||||
_offset = hdr.getEndPos();
|
||||
@ -226,7 +232,7 @@ void Compress::addDirectory(const Poco::Path& entryName, const Poco::DateTime& l
|
||||
poco_assert (_out);
|
||||
ZipFileInfo nfo(hdr);
|
||||
nfo.setOffset(localHeaderOffset);
|
||||
nfo.setZip64Data();
|
||||
nfo.setZip64Data();
|
||||
_infos.insert(std::make_pair(entryName.toString(Poco::Path::PATH_UNIX), nfo));
|
||||
EDone.notify(this, hdr);
|
||||
}
|
||||
@ -295,12 +301,12 @@ ZipArchive Compress::close()
|
||||
// write all infos
|
||||
ZipArchive::FileInfos::const_iterator it = _infos.begin();
|
||||
ZipArchive::FileInfos::const_iterator itEnd = _infos.end();
|
||||
bool needZip64 = _forceZip64;
|
||||
needZip64 = needZip64 || _files.size() >= ZipCommon::ZIP64_MAGIC_SHORT || centralDirStart64 >= ZipCommon::ZIP64_MAGIC;
|
||||
bool needZip64 = _forceZip64;
|
||||
needZip64 = needZip64 || _files.size() >= ZipCommon::ZIP64_MAGIC_SHORT || centralDirStart64 >= ZipCommon::ZIP64_MAGIC;
|
||||
for (; it != itEnd; ++it)
|
||||
{
|
||||
const ZipFileInfo& nfo = it->second;
|
||||
needZip64 = needZip64 || nfo.needsZip64();
|
||||
needZip64 = needZip64 || nfo.needsZip64();
|
||||
|
||||
std::string info(nfo.createHeader());
|
||||
_out.write(info.c_str(), static_cast<std::streamsize>(info.size()));
|
||||
@ -311,26 +317,27 @@ ZipArchive Compress::close()
|
||||
poco_assert (_out);
|
||||
|
||||
Poco::UInt64 numEntries64 = _infos.size();
|
||||
needZip64 = needZip64 || _offset >= ZipCommon::ZIP64_MAGIC;
|
||||
if(needZip64) {
|
||||
ZipArchiveInfo64 central;
|
||||
central.setCentralDirectorySize(centralDirSize64);
|
||||
central.setCentralDirectoryOffset(centralDirStart64);
|
||||
central.setNumberOfEntries(numEntries64);
|
||||
central.setTotalNumberOfEntries(numEntries64);
|
||||
central.setHeaderOffset(_offset);
|
||||
central.setTotalNumberOfDisks(1);
|
||||
std::string centr(central.createHeader());
|
||||
_out.write(centr.c_str(), static_cast<std::streamsize>(centr.size()));
|
||||
_out.flush();
|
||||
_offset += centr.size();
|
||||
_dirs64.insert(std::make_pair(0, central));
|
||||
}
|
||||
needZip64 = needZip64 || _offset >= ZipCommon::ZIP64_MAGIC;
|
||||
if(needZip64)
|
||||
{
|
||||
ZipArchiveInfo64 central;
|
||||
central.setCentralDirectorySize(centralDirSize64);
|
||||
central.setCentralDirectoryOffset(centralDirStart64);
|
||||
central.setNumberOfEntries(numEntries64);
|
||||
central.setTotalNumberOfEntries(numEntries64);
|
||||
central.setHeaderOffset(_offset);
|
||||
central.setTotalNumberOfDisks(1);
|
||||
std::string centr(central.createHeader());
|
||||
_out.write(centr.c_str(), static_cast<std::streamsize>(centr.size()));
|
||||
_out.flush();
|
||||
_offset += centr.size();
|
||||
_dirs64.insert(std::make_pair(0, central));
|
||||
}
|
||||
|
||||
Poco::UInt16 numEntries = numEntries64 >= ZipCommon::ZIP64_MAGIC_SHORT ? ZipCommon::ZIP64_MAGIC_SHORT : static_cast<Poco::UInt16>(numEntries64);
|
||||
Poco::UInt32 centralDirStart = centralDirStart64 >= ZipCommon::ZIP64_MAGIC ? ZipCommon::ZIP64_MAGIC : static_cast<Poco::UInt32>(centralDirStart64);
|
||||
Poco::UInt32 centralDirSize = centralDirSize64 >= ZipCommon::ZIP64_MAGIC ? ZipCommon::ZIP64_MAGIC : static_cast<Poco::UInt32>(centralDirSize64);
|
||||
Poco::UInt32 offset = _offset >= ZipCommon::ZIP64_MAGIC ? ZipCommon::ZIP64_MAGIC : static_cast<Poco::UInt32>(_offset);
|
||||
Poco::UInt16 numEntries = numEntries64 >= ZipCommon::ZIP64_MAGIC_SHORT ? ZipCommon::ZIP64_MAGIC_SHORT : static_cast<Poco::UInt16>(numEntries64);
|
||||
Poco::UInt32 centralDirStart = centralDirStart64 >= ZipCommon::ZIP64_MAGIC ? ZipCommon::ZIP64_MAGIC : static_cast<Poco::UInt32>(centralDirStart64);
|
||||
Poco::UInt32 centralDirSize = centralDirSize64 >= ZipCommon::ZIP64_MAGIC ? ZipCommon::ZIP64_MAGIC : static_cast<Poco::UInt32>(centralDirSize64);
|
||||
Poco::UInt32 offset = _offset >= ZipCommon::ZIP64_MAGIC ? ZipCommon::ZIP64_MAGIC : static_cast<Poco::UInt32>(_offset);
|
||||
ZipArchiveInfo central;
|
||||
central.setCentralDirectorySize(centralDirSize);
|
||||
central.setCentralDirectoryOffset(centralDirStart);
|
||||
@ -344,11 +351,12 @@ ZipArchive Compress::close()
|
||||
std::string centr(central.createHeader());
|
||||
_out.write(centr.c_str(), static_cast<std::streamsize>(centr.size()));
|
||||
_out.flush();
|
||||
_offset += centr.size();
|
||||
_offset += centr.size();
|
||||
_dirs.insert(std::make_pair(0, central));
|
||||
return ZipArchive(_files, _infos, _dirs, _dirs64);
|
||||
}
|
||||
|
||||
|
||||
void Compress::setStoreExtensions(const std::set<std::string>& extensions)
|
||||
{
|
||||
_storeExtensions.clear();
|
||||
|
@ -5,12 +5,12 @@
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: ZipArchive
|
||||
// Module: ZipArchive
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
|
@ -5,12 +5,12 @@
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: ZipArchiveInfo
|
||||
// Module: ZipArchiveInfo
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
@ -38,6 +38,7 @@ ZipArchiveInfo::ZipArchiveInfo(std::istream& in, bool assumeHeaderRead):
|
||||
parse(in, assumeHeaderRead);
|
||||
}
|
||||
|
||||
|
||||
ZipArchiveInfo::ZipArchiveInfo():
|
||||
_rawInfo(),
|
||||
_startPos(0),
|
||||
@ -111,16 +112,17 @@ ZipArchiveInfo64::ZipArchiveInfo64(std::istream& in, bool assumeHeaderRead):
|
||||
parse(in, assumeHeaderRead);
|
||||
}
|
||||
|
||||
|
||||
ZipArchiveInfo64::ZipArchiveInfo64():
|
||||
_rawInfo(),
|
||||
_startPos(0)
|
||||
{
|
||||
std::memset(_rawInfo, 0, FULL_HEADER_SIZE);
|
||||
std::memcpy(_rawInfo, HEADER, ZipCommon::HEADER_SIZE);
|
||||
ZipUtil::set64BitValue(FULL_HEADER_SIZE - (RECORDSIZE_POS + RECORDSIZE_SIZE), _rawInfo, RECORDSIZE_POS);
|
||||
ZipUtil::set64BitValue(FULL_HEADER_SIZE - (RECORDSIZE_POS + RECORDSIZE_SIZE), _rawInfo, RECORDSIZE_POS);
|
||||
std::memset(_locInfo, 0, FULL_LOCATOR_SIZE);
|
||||
std::memcpy(_locInfo, LOCATOR_HEADER, ZipCommon::HEADER_SIZE);
|
||||
setRequiredVersion(4, 5);
|
||||
setRequiredVersion(4, 5);
|
||||
}
|
||||
|
||||
|
||||
@ -143,21 +145,24 @@ void ZipArchiveInfo64::parse(std::istream& inp, bool assumeHeaderRead)
|
||||
std::memset(_rawInfo + ZipCommon::HEADER_SIZE, 0, FULL_HEADER_SIZE - ZipCommon::HEADER_SIZE);
|
||||
|
||||
// read the rest of the header
|
||||
Poco::UInt64 offset = RECORDSIZE_POS;
|
||||
Poco::UInt64 offset = RECORDSIZE_POS;
|
||||
inp.read(_rawInfo + ZipCommon::HEADER_SIZE, RECORDSIZE_SIZE);
|
||||
offset += RECORDSIZE_SIZE;
|
||||
Poco::UInt64 len = ZipUtil::get64BitValue(_rawInfo, RECORDSIZE_POS);
|
||||
if(len <= FULL_HEADER_SIZE - offset) {
|
||||
inp.read(_rawInfo + offset, len);
|
||||
ZipUtil::set64BitValue(FULL_HEADER_SIZE - offset, _rawInfo, RECORDSIZE_POS);
|
||||
} else {
|
||||
inp.read(_rawInfo + offset, FULL_HEADER_SIZE - offset);
|
||||
len -= (FULL_HEADER_SIZE - offset);
|
||||
Poco::Buffer<char> xtra(len);
|
||||
inp.read(xtra.begin(), len);
|
||||
_extraField = std::string(xtra.begin(), len);
|
||||
ZipUtil::set64BitValue(FULL_HEADER_SIZE + len - offset, _rawInfo, RECORDSIZE_POS);
|
||||
}
|
||||
offset += RECORDSIZE_SIZE;
|
||||
Poco::UInt64 len = ZipUtil::get64BitValue(_rawInfo, RECORDSIZE_POS);
|
||||
if (len <= FULL_HEADER_SIZE - offset)
|
||||
{
|
||||
inp.read(_rawInfo + offset, len);
|
||||
ZipUtil::set64BitValue(FULL_HEADER_SIZE - offset, _rawInfo, RECORDSIZE_POS);
|
||||
}
|
||||
else
|
||||
{
|
||||
inp.read(_rawInfo + offset, FULL_HEADER_SIZE - offset);
|
||||
len -= (FULL_HEADER_SIZE - offset);
|
||||
Poco::Buffer<char> xtra(len);
|
||||
inp.read(xtra.begin(), len);
|
||||
_extraField = std::string(xtra.begin(), len);
|
||||
ZipUtil::set64BitValue(FULL_HEADER_SIZE + len - offset, _rawInfo, RECORDSIZE_POS);
|
||||
}
|
||||
inp.read(_locInfo, FULL_LOCATOR_SIZE);
|
||||
poco_assert (std::memcmp(_locInfo, LOCATOR_HEADER, ZipCommon::HEADER_SIZE) == 0);
|
||||
}
|
||||
@ -171,4 +176,5 @@ std::string ZipArchiveInfo64::createHeader() const
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
@ -5,32 +5,12 @@
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: ZipFileInfo
|
||||
// Module: ZipFileInfo
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
@ -53,7 +33,7 @@ ZipFileInfo::ZipFileInfo(const ZipLocalFileHeader& header):
|
||||
_crc32(0),
|
||||
_compressedSize(0),
|
||||
_uncompressedSize(0),
|
||||
_localHeaderOffset(0),
|
||||
_localHeaderOffset(0),
|
||||
_fileName(),
|
||||
_lastModifiedAt(),
|
||||
_extraField()
|
||||
@ -72,9 +52,9 @@ ZipFileInfo::ZipFileInfo(const ZipLocalFileHeader& header):
|
||||
setFileName(header.getFileName());
|
||||
|
||||
if (getHostSystem() == ZipCommon::HS_UNIX)
|
||||
setUnixAttributes();
|
||||
setUnixAttributes();
|
||||
|
||||
_rawInfo[GENERAL_PURPOSE_POS+1] |= 0x08; // Set "language encoding flag" to indicate that filenames and paths are in UTF-8. ZipFileInfo::ZipFileInfo(const ZipLocalFileHeader& header):
|
||||
_rawInfo[GENERAL_PURPOSE_POS+1] |= 0x08; // Set "language encoding flag" to indicate that filenames and paths are in UTF-8. ZipFileInfo::ZipFileInfo(const ZipLocalFileHeader& header):
|
||||
}
|
||||
|
||||
|
||||
@ -83,7 +63,7 @@ ZipFileInfo::ZipFileInfo(std::istream& in, bool assumeHeaderRead):
|
||||
_crc32(0),
|
||||
_compressedSize(0),
|
||||
_uncompressedSize(0),
|
||||
_localHeaderOffset(0),
|
||||
_localHeaderOffset(0),
|
||||
_fileName(),
|
||||
_lastModifiedAt(),
|
||||
_extraField()
|
||||
@ -126,25 +106,25 @@ void ZipFileInfo::parse(std::istream& inp, bool assumeHeaderRead)
|
||||
Poco::Buffer<char> xtra(len);
|
||||
inp.read(xtra.begin(), len);
|
||||
_extraField = std::string(xtra.begin(), len);
|
||||
char* ptr = xtra.begin();
|
||||
while(ptr <= xtra.begin() + len - 4) {
|
||||
Poco::UInt16 id = ZipUtil::get16BitValue(ptr, 0); ptr +=2;
|
||||
Poco::UInt16 size = ZipUtil::get16BitValue(ptr, 0); ptr += 2;
|
||||
if(id == ZipCommon::ZIP64_EXTRA_ID) {
|
||||
poco_assert(size >= 8);
|
||||
if(getUncompressedSizeFromHeader() == ZipCommon::ZIP64_MAGIC) {
|
||||
setUncompressedSize(ZipUtil::get64BitValue(ptr, 0)); size -= 8; ptr += 8;
|
||||
}
|
||||
if(size >= 8 && getCompressedSizeFromHeader() == ZipCommon::ZIP64_MAGIC) {
|
||||
setCompressedSize(ZipUtil::get64BitValue(ptr, 0)); size -= 8; ptr += 8;
|
||||
}
|
||||
if(size >= 8 && getOffsetFromHeader() == ZipCommon::ZIP64_MAGIC) {
|
||||
setOffset(ZipUtil::get64BitValue(ptr, 0)); size -= 8; ptr += 8;
|
||||
}
|
||||
} else {
|
||||
ptr += size;
|
||||
}
|
||||
}
|
||||
char* ptr = xtra.begin();
|
||||
while(ptr <= xtra.begin() + len - 4) {
|
||||
Poco::UInt16 id = ZipUtil::get16BitValue(ptr, 0); ptr +=2;
|
||||
Poco::UInt16 size = ZipUtil::get16BitValue(ptr, 0); ptr += 2;
|
||||
if(id == ZipCommon::ZIP64_EXTRA_ID) {
|
||||
poco_assert(size >= 8);
|
||||
if(getUncompressedSizeFromHeader() == ZipCommon::ZIP64_MAGIC) {
|
||||
setUncompressedSize(ZipUtil::get64BitValue(ptr, 0)); size -= 8; ptr += 8;
|
||||
}
|
||||
if(size >= 8 && getCompressedSizeFromHeader() == ZipCommon::ZIP64_MAGIC) {
|
||||
setCompressedSize(ZipUtil::get64BitValue(ptr, 0)); size -= 8; ptr += 8;
|
||||
}
|
||||
if(size >= 8 && getOffsetFromHeader() == ZipCommon::ZIP64_MAGIC) {
|
||||
setOffset(ZipUtil::get64BitValue(ptr, 0)); size -= 8; ptr += 8;
|
||||
}
|
||||
} else {
|
||||
ptr += size;
|
||||
}
|
||||
}
|
||||
}
|
||||
len = getFileCommentLength();
|
||||
if (len > 0)
|
||||
|
@ -10,27 +10,7 @@
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
@ -51,88 +31,91 @@ const char ZipLocalFileHeader::HEADER[ZipCommon::HEADER_SIZE] = {'\x50', '\x4b',
|
||||
|
||||
|
||||
ZipLocalFileHeader::ZipLocalFileHeader(const Poco::Path& fileName,
|
||||
const Poco::DateTime& lastModifiedAt,
|
||||
ZipCommon::CompressionMethod cm,
|
||||
ZipCommon::CompressionLevel cl,
|
||||
const Poco::DateTime& lastModifiedAt,
|
||||
ZipCommon::CompressionMethod cm,
|
||||
ZipCommon::CompressionLevel cl,
|
||||
bool forceZip64):
|
||||
_forceZip64(forceZip64),
|
||||
_forceZip64(forceZip64),
|
||||
_rawHeader(),
|
||||
_startPos(-1),
|
||||
_endPos(-1),
|
||||
_fileName(),
|
||||
_lastModifiedAt(),
|
||||
_extraField(),
|
||||
_crc32(0),
|
||||
_compressedSize(0),
|
||||
_uncompressedSize(0)
|
||||
_startPos(-1),
|
||||
_endPos(-1),
|
||||
_fileName(),
|
||||
_lastModifiedAt(),
|
||||
_extraField(),
|
||||
_crc32(0),
|
||||
_compressedSize(0),
|
||||
_uncompressedSize(0)
|
||||
{
|
||||
std::memcpy(_rawHeader, HEADER, ZipCommon::HEADER_SIZE);
|
||||
std::memset(_rawHeader+ZipCommon::HEADER_SIZE, 0, FULLHEADER_SIZE - ZipCommon::HEADER_SIZE);
|
||||
ZipCommon::HostSystem hs = ZipCommon::HS_FAT;
|
||||
std::memcpy(_rawHeader, HEADER, ZipCommon::HEADER_SIZE);
|
||||
std::memset(_rawHeader+ZipCommon::HEADER_SIZE, 0, FULLHEADER_SIZE - ZipCommon::HEADER_SIZE);
|
||||
ZipCommon::HostSystem hs = ZipCommon::HS_FAT;
|
||||
|
||||
#if (POCO_OS == POCO_OS_CYGWIN)
|
||||
hs = ZipCommon::HS_UNIX;
|
||||
hs = ZipCommon::HS_UNIX;
|
||||
#endif
|
||||
#if (POCO_OS == POCO_OS_VMS)
|
||||
hs = ZipCommon::HS_VMS;
|
||||
hs = ZipCommon::HS_VMS;
|
||||
#endif
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
hs = ZipCommon::HS_UNIX;
|
||||
hs = ZipCommon::HS_UNIX;
|
||||
#endif
|
||||
setHostSystem(hs);
|
||||
setEncryption(false);
|
||||
setExtraFieldSize(0);
|
||||
setLastModifiedAt(lastModifiedAt);
|
||||
init(fileName, cm, cl);
|
||||
setHostSystem(hs);
|
||||
setEncryption(false);
|
||||
setExtraFieldSize(0);
|
||||
setLastModifiedAt(lastModifiedAt);
|
||||
init(fileName, cm, cl);
|
||||
}
|
||||
|
||||
|
||||
ZipLocalFileHeader::ZipLocalFileHeader(std::istream& inp, bool assumeHeaderRead, ParseCallback& callback):
|
||||
_forceZip64(false),
|
||||
_rawHeader(),
|
||||
_startPos(inp.tellg()),
|
||||
_endPos(-1),
|
||||
_fileName(),
|
||||
_lastModifiedAt(),
|
||||
_extraField(),
|
||||
_crc32(0),
|
||||
_compressedSize(0),
|
||||
_uncompressedSize(0)
|
||||
_forceZip64(false),
|
||||
_rawHeader(),
|
||||
_startPos(inp.tellg()),
|
||||
_endPos(-1),
|
||||
_fileName(),
|
||||
_lastModifiedAt(),
|
||||
_extraField(),
|
||||
_crc32(0),
|
||||
_compressedSize(0),
|
||||
_uncompressedSize(0)
|
||||
{
|
||||
poco_assert_dbg( (EXTRA_FIELD_POS+EXTRA_FIELD_LENGTH) == FULLHEADER_SIZE);
|
||||
poco_assert_dbg( (EXTRA_FIELD_POS+EXTRA_FIELD_LENGTH) == FULLHEADER_SIZE);
|
||||
|
||||
if (assumeHeaderRead)
|
||||
_startPos -= ZipCommon::HEADER_SIZE;
|
||||
if (assumeHeaderRead)
|
||||
_startPos -= ZipCommon::HEADER_SIZE;
|
||||
|
||||
parse(inp, assumeHeaderRead);
|
||||
parse(inp, assumeHeaderRead);
|
||||
|
||||
bool ok = callback.handleZipEntry(inp, *this);
|
||||
bool ok = callback.handleZipEntry(inp, *this);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
if (searchCRCAndSizesAfterData())
|
||||
{
|
||||
if (ok)
|
||||
{
|
||||
if (searchCRCAndSizesAfterData())
|
||||
{
|
||||
char header[ZipCommon::HEADER_SIZE]={'\x00', '\x00', '\x00', '\x00'};
|
||||
inp.read(header, ZipCommon::HEADER_SIZE);
|
||||
if(::memcmp(header, ZipDataInfo64::HEADER, sizeof(header)) == 0) {
|
||||
if (std::memcmp(header, ZipDataInfo64::HEADER, sizeof(header)) == 0)
|
||||
{
|
||||
ZipDataInfo64 nfo(inp, true);
|
||||
setCRC(nfo.getCRC32());
|
||||
setCompressedSize(nfo.getCompressedSize());
|
||||
setUncompressedSize(nfo.getUncompressedSize());
|
||||
} else {
|
||||
setCRC(nfo.getCRC32());
|
||||
setCompressedSize(nfo.getCompressedSize());
|
||||
setUncompressedSize(nfo.getUncompressedSize());
|
||||
}
|
||||
else
|
||||
{
|
||||
ZipDataInfo nfo(inp, true);
|
||||
setCRC(nfo.getCRC32());
|
||||
setCompressedSize(nfo.getCompressedSize());
|
||||
setUncompressedSize(nfo.getUncompressedSize());
|
||||
setCRC(nfo.getCRC32());
|
||||
setCompressedSize(nfo.getCompressedSize());
|
||||
setUncompressedSize(nfo.getUncompressedSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
poco_assert_dbg(!searchCRCAndSizesAfterData());
|
||||
ZipUtil::sync(inp);
|
||||
}
|
||||
_endPos = _startPos + getHeaderSize() + _compressedSize; // exclude the data block!
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
poco_assert_dbg(!searchCRCAndSizesAfterData());
|
||||
ZipUtil::sync(inp);
|
||||
}
|
||||
_endPos = _startPos + getHeaderSize() + _compressedSize; // exclude the data block!
|
||||
}
|
||||
|
||||
|
||||
@ -143,118 +126,122 @@ ZipLocalFileHeader::~ZipLocalFileHeader()
|
||||
|
||||
void ZipLocalFileHeader::parse(std::istream& inp, bool assumeHeaderRead)
|
||||
{
|
||||
if (!assumeHeaderRead)
|
||||
{
|
||||
inp.read(_rawHeader, ZipCommon::HEADER_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::memcpy(_rawHeader, HEADER, ZipCommon::HEADER_SIZE);
|
||||
}
|
||||
poco_assert (std::memcmp(_rawHeader, HEADER, ZipCommon::HEADER_SIZE) == 0);
|
||||
// read the rest of the header
|
||||
inp.read(_rawHeader + ZipCommon::HEADER_SIZE, FULLHEADER_SIZE - ZipCommon::HEADER_SIZE);
|
||||
poco_assert (_rawHeader[VERSION_POS + 1]>= ZipCommon::HS_FAT && _rawHeader[VERSION_POS + 1] < ZipCommon::HS_UNUSED);
|
||||
poco_assert (getMajorVersionNumber() <= 4); // Allow for Zip64 version 4.5
|
||||
poco_assert (ZipUtil::get16BitValue(_rawHeader, COMPR_METHOD_POS) < ZipCommon::CM_UNUSED);
|
||||
parseDateTime();
|
||||
Poco::UInt16 len = getFileNameLength();
|
||||
Poco::Buffer<char> buf(len);
|
||||
inp.read(buf.begin(), len);
|
||||
_fileName = std::string(buf.begin(), len);
|
||||
if (!assumeHeaderRead)
|
||||
{
|
||||
inp.read(_rawHeader, ZipCommon::HEADER_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::memcpy(_rawHeader, HEADER, ZipCommon::HEADER_SIZE);
|
||||
}
|
||||
poco_assert (std::memcmp(_rawHeader, HEADER, ZipCommon::HEADER_SIZE) == 0);
|
||||
// read the rest of the header
|
||||
inp.read(_rawHeader + ZipCommon::HEADER_SIZE, FULLHEADER_SIZE - ZipCommon::HEADER_SIZE);
|
||||
poco_assert (_rawHeader[VERSION_POS + 1]>= ZipCommon::HS_FAT && _rawHeader[VERSION_POS + 1] < ZipCommon::HS_UNUSED);
|
||||
poco_assert (getMajorVersionNumber() <= 4); // Allow for Zip64 version 4.5
|
||||
poco_assert (ZipUtil::get16BitValue(_rawHeader, COMPR_METHOD_POS) < ZipCommon::CM_UNUSED);
|
||||
parseDateTime();
|
||||
Poco::UInt16 len = getFileNameLength();
|
||||
Poco::Buffer<char> buf(len);
|
||||
inp.read(buf.begin(), len);
|
||||
_fileName = std::string(buf.begin(), len);
|
||||
|
||||
if (!searchCRCAndSizesAfterData())
|
||||
{
|
||||
_crc32 = getCRCFromHeader();
|
||||
_compressedSize = getCompressedSizeFromHeader();
|
||||
_uncompressedSize = getUncompressedSizeFromHeader();
|
||||
}
|
||||
if (!searchCRCAndSizesAfterData())
|
||||
{
|
||||
_crc32 = getCRCFromHeader();
|
||||
_compressedSize = getCompressedSizeFromHeader();
|
||||
_uncompressedSize = getUncompressedSizeFromHeader();
|
||||
}
|
||||
|
||||
if (hasExtraField())
|
||||
{
|
||||
len = getExtraFieldLength();
|
||||
Poco::Buffer<char> xtra(len);
|
||||
inp.read(xtra.begin(), len);
|
||||
_extraField = std::string(xtra.begin(), len);
|
||||
{
|
||||
len = getExtraFieldLength();
|
||||
Poco::Buffer<char> xtra(len);
|
||||
inp.read(xtra.begin(), len);
|
||||
_extraField = std::string(xtra.begin(), len);
|
||||
char* ptr = xtra.begin();
|
||||
while(ptr <= xtra.begin() + len - 4) {
|
||||
while (ptr <= xtra.begin() + len - 4)
|
||||
{
|
||||
Poco::UInt16 id = ZipUtil::get16BitValue(ptr, 0); ptr +=2;
|
||||
Poco::UInt16 size = ZipUtil::get16BitValue(ptr, 0); ptr += 2;
|
||||
if(id == ZipCommon::ZIP64_EXTRA_ID) {
|
||||
if (id == ZipCommon::ZIP64_EXTRA_ID)
|
||||
{
|
||||
poco_assert(size >= 8);
|
||||
if(getUncompressedSizeFromHeader() == ZipCommon::ZIP64_MAGIC) {
|
||||
if (getUncompressedSizeFromHeader() == ZipCommon::ZIP64_MAGIC)
|
||||
{
|
||||
setUncompressedSize(ZipUtil::get64BitValue(ptr, 0)); size -= 8; ptr += 8;
|
||||
}
|
||||
if(size >= 8 && getCompressedSizeFromHeader() == ZipCommon::ZIP64_MAGIC) {
|
||||
if (size >= 8 && getCompressedSizeFromHeader() == ZipCommon::ZIP64_MAGIC)
|
||||
{
|
||||
setCompressedSize(ZipUtil::get64BitValue(ptr, 0)); size -= 8; ptr += 8;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr += size;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool ZipLocalFileHeader::searchCRCAndSizesAfterData() const
|
||||
{
|
||||
if (getCompressionMethod() == ZipCommon::CM_DEFLATE)
|
||||
{
|
||||
// check bit 3
|
||||
return ((ZipUtil::get16BitValue(_rawHeader, GENERAL_PURPOSE_POS) & 0x0008) != 0);
|
||||
}
|
||||
return false;
|
||||
if (getCompressionMethod() == ZipCommon::CM_DEFLATE)
|
||||
{
|
||||
// check bit 3
|
||||
return ((ZipUtil::get16BitValue(_rawHeader, GENERAL_PURPOSE_POS) & 0x0008) != 0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void ZipLocalFileHeader::setFileName(const std::string& fileName, bool isDirectory)
|
||||
{
|
||||
poco_assert (!fileName.empty());
|
||||
Poco::Path aPath(fileName);
|
||||
poco_assert (!fileName.empty());
|
||||
Poco::Path aPath(fileName);
|
||||
|
||||
if (isDirectory)
|
||||
{
|
||||
aPath.makeDirectory();
|
||||
setCRC(0);
|
||||
setCompressedSize(0);
|
||||
setUncompressedSize(0);
|
||||
setCompressionMethod(ZipCommon::CM_STORE);
|
||||
setCompressionLevel(ZipCommon::CL_NORMAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
aPath.makeFile();
|
||||
}
|
||||
_fileName = aPath.toString(Poco::Path::PATH_UNIX);
|
||||
if (_fileName[0] == '/')
|
||||
_fileName = _fileName.substr(1);
|
||||
if (isDirectory)
|
||||
{
|
||||
poco_assert_dbg (_fileName[_fileName.size()-1] == '/');
|
||||
}
|
||||
setFileNameLength(static_cast<Poco::UInt16>(_fileName.size()));
|
||||
if (isDirectory)
|
||||
{
|
||||
aPath.makeDirectory();
|
||||
setCRC(0);
|
||||
setCompressedSize(0);
|
||||
setUncompressedSize(0);
|
||||
setCompressionMethod(ZipCommon::CM_STORE);
|
||||
setCompressionLevel(ZipCommon::CL_NORMAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
aPath.makeFile();
|
||||
}
|
||||
_fileName = aPath.toString(Poco::Path::PATH_UNIX);
|
||||
if (_fileName[0] == '/')
|
||||
_fileName = _fileName.substr(1);
|
||||
if (isDirectory)
|
||||
{
|
||||
poco_assert_dbg (_fileName[_fileName.size()-1] == '/');
|
||||
}
|
||||
setFileNameLength(static_cast<Poco::UInt16>(_fileName.size()));
|
||||
}
|
||||
|
||||
|
||||
void ZipLocalFileHeader::init( const Poco::Path& fName,
|
||||
ZipCommon::CompressionMethod cm,
|
||||
ZipCommon::CompressionLevel cl)
|
||||
void ZipLocalFileHeader::init(const Poco::Path& fName, ZipCommon::CompressionMethod cm, ZipCommon::CompressionLevel cl)
|
||||
{
|
||||
poco_assert (_fileName.empty());
|
||||
setSearchCRCAndSizesAfterData(false);
|
||||
Poco::Path fileName(fName);
|
||||
fileName.setDevice(""); // clear device!
|
||||
setFileName(fileName.toString(Poco::Path::PATH_UNIX), fileName.isDirectory());
|
||||
setRequiredVersion(2, 0);
|
||||
if (fileName.isFile())
|
||||
{
|
||||
setCompressionMethod(cm);
|
||||
setCompressionLevel(cl);
|
||||
}
|
||||
else
|
||||
setCompressionMethod(ZipCommon::CM_STORE);
|
||||
if(_forceZip64)
|
||||
poco_assert (_fileName.empty());
|
||||
setSearchCRCAndSizesAfterData(false);
|
||||
Poco::Path fileName(fName);
|
||||
fileName.setDevice(""); // clear device!
|
||||
setFileName(fileName.toString(Poco::Path::PATH_UNIX), fileName.isDirectory());
|
||||
setRequiredVersion(2, 0);
|
||||
if (fileName.isFile())
|
||||
{
|
||||
setCompressionMethod(cm);
|
||||
setCompressionLevel(cl);
|
||||
}
|
||||
else
|
||||
setCompressionMethod(ZipCommon::CM_STORE);
|
||||
if (_forceZip64)
|
||||
setZip64Data();
|
||||
_rawHeader[GENERAL_PURPOSE_POS+1] |= 0x08; // Set "language encoding flag" to indicate that filenames and paths are in UTF-8.
|
||||
}
|
||||
@ -262,10 +249,10 @@ void ZipLocalFileHeader::init( const Poco::Path& fName,
|
||||
|
||||
std::string ZipLocalFileHeader::createHeader() const
|
||||
{
|
||||
std::string result(_rawHeader, FULLHEADER_SIZE);
|
||||
result.append(_fileName);
|
||||
result.append(_extraField);
|
||||
return result;
|
||||
std::string result(_rawHeader, FULLHEADER_SIZE);
|
||||
result.append(_fileName);
|
||||
result.append(_extraField);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
@ -135,7 +135,7 @@ ZipStreamBuf::ZipStreamBuf(std::ostream& ostr, ZipLocalFileHeader& fileEntry, bo
|
||||
else throw Poco::NotImplementedException("Unsupported compression method");
|
||||
|
||||
// now write the header to the ostr!
|
||||
if(fileEntry.needsZip64())
|
||||
if (fileEntry.needsZip64())
|
||||
fileEntry.setZip64Data();
|
||||
std::string header = fileEntry.createHeader();
|
||||
ostr.write(header.c_str(), static_cast<std::streamsize>(header.size()));
|
||||
@ -220,14 +220,17 @@ void ZipStreamBuf::close(Poco::UInt64& extraDataSize)
|
||||
// or fix the crc entries
|
||||
if (_pHeader->searchCRCAndSizesAfterData())
|
||||
{
|
||||
if(_pHeader->needsZip64()) {
|
||||
if (_pHeader->needsZip64())
|
||||
{
|
||||
ZipDataInfo64 info;
|
||||
info.setCRC32(_crc32.checksum());
|
||||
info.setUncompressedSize(_bytesWritten);
|
||||
info.setCompressedSize(_ptrOHelper->bytesWritten());
|
||||
extraDataSize = info.getFullHeaderSize();
|
||||
_pOstr->write(info.getRawHeader(), static_cast<std::streamsize>(extraDataSize));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
ZipDataInfo info;
|
||||
info.setCRC32(_crc32.checksum());
|
||||
info.setUncompressedSize(static_cast<Poco::UInt32>(_bytesWritten));
|
||||
@ -245,7 +248,7 @@ void ZipStreamBuf::close(Poco::UInt64& extraDataSize)
|
||||
_pOstr->seekp(_pHeader->getStartPos(), std::ios_base::beg);
|
||||
poco_assert (*_pOstr);
|
||||
_pHeader->setStartPos(_pHeader->getStartPos()); // This resets EndPos now that compressed Size is known
|
||||
if(_pHeader->hasExtraField()) // Update sizes in header extension.
|
||||
if (_pHeader->hasExtraField()) // Update sizes in header extension.
|
||||
_pHeader->setZip64Data();
|
||||
std::string header = _pHeader->createHeader();
|
||||
_pOstr->write(header.c_str(), static_cast<std::streamsize>(header.size()));
|
||||
|
@ -6,26 +6,24 @@
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "CompressTest.h"
|
||||
#include "ZipTest.h"
|
||||
|
||||
#include "Poco/Buffer.h"
|
||||
#include "Poco/Zip/Compress.h"
|
||||
#include "Poco/Zip/ZipManipulator.h"
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/FileStream.h"
|
||||
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include <fstream>
|
||||
|
||||
#undef min
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
using namespace Poco::Zip;
|
||||
|
||||
|
||||
@ -138,51 +136,58 @@ void CompressTest::testSetZipComment()
|
||||
assert(a.getZipComment() == comment);
|
||||
}
|
||||
|
||||
void CompressTest::createDataFile(const std::string& path, Poco::UInt64 size) {
|
||||
std::ofstream out(path, std::ios::binary | std::ios::trunc);
|
||||
assert( ! out.fail() );
|
||||
Poco::Buffer<char> buffer(MB);
|
||||
for(int i = 0; size != 0; i++) {
|
||||
std::memset(buffer.begin(), i, buffer.size());
|
||||
Poco::UInt64 bytesToWrite = std::min(size, buffer.size());
|
||||
out.write(buffer.begin(), bytesToWrite);
|
||||
assert( ! out.fail() );
|
||||
size -= bytesToWrite;
|
||||
}
|
||||
out.flush();
|
||||
assert( ! out.fail() );
|
||||
out.close();
|
||||
assert( ! out.fail() );
|
||||
|
||||
void CompressTest::createDataFile(const std::string& path, Poco::UInt64 size)
|
||||
{
|
||||
std::ofstream out(path, std::ios::binary | std::ios::trunc);
|
||||
assert( ! out.fail() );
|
||||
Poco::Buffer<char> buffer(MB);
|
||||
for(int i = 0; size != 0; i++) {
|
||||
std::memset(buffer.begin(), i, buffer.size());
|
||||
Poco::UInt64 bytesToWrite = std::min(size, buffer.size());
|
||||
out.write(buffer.begin(), bytesToWrite);
|
||||
assert( ! out.fail() );
|
||||
size -= bytesToWrite;
|
||||
}
|
||||
out.flush();
|
||||
assert( ! out.fail() );
|
||||
out.close();
|
||||
assert( ! out.fail() );
|
||||
}
|
||||
|
||||
|
||||
void CompressTest::testZip64()
|
||||
{
|
||||
std::map<std::string, Poco::UInt64> files;
|
||||
files["data1.bin"] = static_cast<Poco::UInt64>(MB)*4096+1;
|
||||
files["data2.bin"] = static_cast<Poco::UInt64>(MB)*16;
|
||||
files["data3.bin"] = static_cast<Poco::UInt64>(MB)*4096-1;
|
||||
|
||||
for(std::map<std::string, Poco::UInt64>::const_iterator it = files.begin(); it != files.end(); it++) {
|
||||
createDataFile(it->first, it->second);
|
||||
}
|
||||
std::map<std::string, Poco::UInt64> files;
|
||||
files["data1.bin"] = static_cast<Poco::UInt64>(MB)*4096+1;
|
||||
files["data2.bin"] = static_cast<Poco::UInt64>(MB)*16;
|
||||
files["data3.bin"] = static_cast<Poco::UInt64>(MB)*4096-1;
|
||||
|
||||
for(std::map<std::string, Poco::UInt64>::const_iterator it = files.begin(); it != files.end(); it++)
|
||||
{
|
||||
createDataFile(it->first, it->second);
|
||||
}
|
||||
std::ofstream out("zip64.zip", std::ios::binary | std::ios::trunc);
|
||||
Compress c(out, true, true);
|
||||
for(std::map<std::string, Poco::UInt64>::const_iterator it = files.begin(); it != files.end(); it++) {
|
||||
const std::string& path = it->first;
|
||||
c.addFile(path, path, ZipCommon::CM_STORE);
|
||||
}
|
||||
ZipArchive a(c.close());
|
||||
for(std::map<std::string, Poco::UInt64>::const_iterator it = files.begin(); it != files.end(); it++) {
|
||||
const std::string& path = it->first;
|
||||
Poco::UInt64 size = it->second;
|
||||
ZipArchive::FileHeaders::const_iterator it2 = a.findHeader(path);
|
||||
assert (it2 != a.headerEnd());
|
||||
const Poco::Zip::ZipLocalFileHeader& file = it2->second;
|
||||
assert(file.getUncompressedSize() == size);
|
||||
assert(file.getCompressedSize() == size);
|
||||
}
|
||||
Compress c(out, true, true);
|
||||
for(std::map<std::string, Poco::UInt64>::const_iterator it = files.begin(); it != files.end(); it++)
|
||||
{
|
||||
const std::string& path = it->first;
|
||||
c.addFile(path, path, ZipCommon::CM_STORE);
|
||||
}
|
||||
ZipArchive a(c.close());
|
||||
for(std::map<std::string, Poco::UInt64>::const_iterator it = files.begin(); it != files.end(); it++)
|
||||
{
|
||||
const std::string& path = it->first;
|
||||
Poco::UInt64 size = it->second;
|
||||
ZipArchive::FileHeaders::const_iterator it2 = a.findHeader(path);
|
||||
assert (it2 != a.headerEnd());
|
||||
const Poco::Zip::ZipLocalFileHeader& file = it2->second;
|
||||
assert(file.getUncompressedSize() == size);
|
||||
assert(file.getCompressedSize() == size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CompressTest::setUp()
|
||||
{
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
#include "Poco/Zip/Zip.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class CompressTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
@ -32,16 +33,15 @@ public:
|
||||
void testManipulatorReplace();
|
||||
void testSetZipComment();
|
||||
|
||||
static const Poco::UInt64 MB = (1024*1024);
|
||||
void createDataFile(const std::string& path, Poco::UInt64 size);
|
||||
void testZip64();
|
||||
static const Poco::UInt64 MB = (1024*1024);
|
||||
void createDataFile(const std::string& path, Poco::UInt64 size);
|
||||
void testZip64();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
@ -25,12 +25,12 @@
|
||||
#include "Poco/StreamCopier.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
#undef min
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using namespace Poco::Zip;
|
||||
|
||||
|
||||
@ -165,45 +165,52 @@ void ZipTest::testDecompressFlat()
|
||||
assert (!dec.mapping().empty());
|
||||
}
|
||||
|
||||
void ZipTest::verifyDataFile(const std::string& path, Poco::UInt64 size) {
|
||||
std::ifstream in(path, std::ios::binary);
|
||||
assert( ! in.fail() );
|
||||
Poco::Buffer<char> buffer1(MB);
|
||||
Poco::Buffer<char> buffer2(MB);
|
||||
for(int i = 0; size != 0; i++) {
|
||||
std::memset(buffer1.begin(), i, buffer1.size());
|
||||
std::memset(buffer2.begin(), 0, buffer2.size());
|
||||
Poco::UInt64 bytesToRead = std::min(size, buffer2.size());
|
||||
in.read(buffer2.begin(), bytesToRead);
|
||||
assert( ! in.fail() );
|
||||
assert( std::memcmp(buffer1.begin(), buffer2.begin(), bytesToRead) == 0);
|
||||
size -= bytesToRead;
|
||||
}
|
||||
char c;
|
||||
in.read(&c, 1);
|
||||
assert ( in.eof() );
|
||||
|
||||
void ZipTest::verifyDataFile(const std::string& path, Poco::UInt64 size)
|
||||
{
|
||||
std::ifstream in(path, std::ios::binary);
|
||||
assert( ! in.fail() );
|
||||
Poco::Buffer<char> buffer1(MB);
|
||||
Poco::Buffer<char> buffer2(MB);
|
||||
for (int i = 0; size != 0; i++)
|
||||
{
|
||||
std::memset(buffer1.begin(), i, buffer1.size());
|
||||
std::memset(buffer2.begin(), 0, buffer2.size());
|
||||
Poco::UInt64 bytesToRead = std::min(size, buffer2.size());
|
||||
in.read(buffer2.begin(), bytesToRead);
|
||||
assert(!in.fail() );
|
||||
assert(std::memcmp(buffer1.begin(), buffer2.begin(), bytesToRead) == 0);
|
||||
size -= bytesToRead;
|
||||
}
|
||||
char c;
|
||||
in.read(&c, 1);
|
||||
assert ( in.eof() );
|
||||
}
|
||||
|
||||
|
||||
void ZipTest::testDecompressZip64()
|
||||
{
|
||||
std::map<std::string, Poco::UInt64> files;
|
||||
files["data1.bin"] = static_cast<Poco::UInt64>(MB)*4096+1;
|
||||
files["data2.bin"] = static_cast<Poco::UInt64>(MB)*16;
|
||||
files["data3.bin"] = static_cast<Poco::UInt64>(MB)*4096-1;
|
||||
|
||||
for(std::map<std::string, Poco::UInt64>::const_iterator it = files.begin(); it != files.end(); it++) {
|
||||
Poco::File file(it->first);
|
||||
if(file.exists())
|
||||
file.remove();
|
||||
}
|
||||
std::map<std::string, Poco::UInt64> files;
|
||||
files["data1.bin"] = static_cast<Poco::UInt64>(MB)*4096+1;
|
||||
files["data2.bin"] = static_cast<Poco::UInt64>(MB)*16;
|
||||
files["data3.bin"] = static_cast<Poco::UInt64>(MB)*4096-1;
|
||||
|
||||
for(std::map<std::string, Poco::UInt64>::const_iterator it = files.begin(); it != files.end(); it++)
|
||||
{
|
||||
Poco::File file(it->first);
|
||||
if(file.exists())
|
||||
file.remove();
|
||||
}
|
||||
std::ifstream in("zip64.zip", std::ios::binary);
|
||||
Decompress c(in, ".");
|
||||
c.decompressAllFiles();
|
||||
for(std::map<std::string, Poco::UInt64>::const_iterator it = files.begin(); it != files.end(); it++) {
|
||||
verifyDataFile(it->first, it->second);
|
||||
}
|
||||
Decompress c(in, ".");
|
||||
c.decompressAllFiles();
|
||||
for(std::map<std::string, Poco::UInt64>::const_iterator it = files.begin(); it != files.end(); it++)
|
||||
{
|
||||
verifyDataFile(it->first, it->second);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ZipTest::onDecompressError(const void* pSender, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string>& info)
|
||||
{
|
||||
++_errCnt;
|
||||
|
@ -8,7 +8,7 @@
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
@ -35,9 +35,9 @@ public:
|
||||
|
||||
void testDecompressFlat();
|
||||
|
||||
static const Poco::UInt64 MB = (1024*1024);
|
||||
void verifyDataFile(const std::string& path, Poco::UInt64 size);
|
||||
void testDecompressZip64();
|
||||
static const Poco::UInt64 MB = (1024*1024);
|
||||
void verifyDataFile(const std::string& path, Poco::UInt64 size);
|
||||
void testDecompressZip64();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
Loading…
x
Reference in New Issue
Block a user