added Zip to trunk

This commit is contained in:
Peter Schojer 2008-10-31 09:18:26 +00:00
parent 4975ac2c44
commit ba13c39636
89 changed files with 12760 additions and 0 deletions

20
Zip/Makefile Normal file
View File

@ -0,0 +1,20 @@
#
# Makefile
#
# $Id: //poco/1.3/Zip/Makefile#2 $
#
# Makefile for Poco Zip
#
include $(POCO_BASE)/build/rules/global
objects = AutoDetectStream Compress Decompress ParseCallback PartialStream \
SkipCallback ZipArchive ZipArchiveInfo ZipDataInfo \
ZipFileInfo ZipLocalFileHeader ZipStream ZipUtil ZipCommon ZipException \
Add Delete Keep Rename Replace ZipManipulator ZipOperation
target = PocoZip
target_version = $(LIBVERSION)
target_libs = PocoFoundation
include $(POCO_BASE)/build/rules/lib

16
Zip/Zip.vmsbuild Normal file
View File

@ -0,0 +1,16 @@
#
# Zip.vmsbuild
#
# $Id: //poco/1.3/Zip/Zip.vmsbuild#1 $
#
LIB=PocoZip
Decompress
ParseCallback
PartialStream
SkipCallback
ZipArchive
ZipArchiveInfo
ZipFileInfo
ZipLocalFileHeader
ZipStream
ZipUtil

30
Zip/Zip_VS71.sln Normal file
View File

@ -0,0 +1,30 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Zip", "Zip_VS71.vcproj", "{4AC75EAD-BFCF-41E6-AB1F-0DA203CC7C61}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestSuite", "testsuite\TestSuite_VS71.vcproj", "{9665FC3C-DB71-4C6C-AAEE-AAFD73CB31E7}"
ProjectSection(ProjectDependencies) = postProject
{4AC75EAD-BFCF-41E6-AB1F-0DA203CC7C61} = {4AC75EAD-BFCF-41E6-AB1F-0DA203CC7C61}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
debug_shared = debug_shared
release_shared = release_shared
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{4AC75EAD-BFCF-41E6-AB1F-0DA203CC7C61}.debug_shared.ActiveCfg = debug_shared|Win32
{4AC75EAD-BFCF-41E6-AB1F-0DA203CC7C61}.debug_shared.Build.0 = debug_shared|Win32
{4AC75EAD-BFCF-41E6-AB1F-0DA203CC7C61}.release_shared.ActiveCfg = release_shared|Win32
{4AC75EAD-BFCF-41E6-AB1F-0DA203CC7C61}.release_shared.Build.0 = release_shared|Win32
{9665FC3C-DB71-4C6C-AAEE-AAFD73CB31E7}.debug_shared.ActiveCfg = debug_shared|Win32
{9665FC3C-DB71-4C6C-AAEE-AAFD73CB31E7}.debug_shared.Build.0 = debug_shared|Win32
{9665FC3C-DB71-4C6C-AAEE-AAFD73CB31E7}.release_shared.ActiveCfg = release_shared|Win32
{9665FC3C-DB71-4C6C-AAEE-AAFD73CB31E7}.release_shared.Build.0 = release_shared|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal

307
Zip/Zip_VS71.vcproj Normal file
View File

@ -0,0 +1,307 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="Zip"
ProjectGUID="{4ac75ead-bfcf-41e6-ab1f-0da203cc7c61}"
RootNamespace="Zip"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared"
ConfigurationType="2"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".\include;..\Foundation\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;POCO_DLL;Zip_EXPORTS"
StringPooling="TRUE"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
BufferSecurityCheck="TRUE"
TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="TRUE"
RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundationd.lib"
OutputFile="..\bin\PocoZipd.dll"
LinkIncremental="2"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories="..\lib"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="..\bin\PocoZipd.pdb"
SubSystem="1"
OptimizeForWindows98="1"
ImportLibrary="..\lib\PocoZipd.lib"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="release_shared|Win32"
OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared"
ConfigurationType="2"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="4"
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="TRUE"
FavorSizeOrSpeed="1"
OmitFramePointers="TRUE"
OptimizeForProcessor="3"
AdditionalIncludeDirectories=".\include;..\Foundation\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;POCO_DLL;Zip_EXPORTS"
GeneratePreprocessedFile="0"
KeepComments="FALSE"
StringPooling="TRUE"
RuntimeLibrary="2"
BufferSecurityCheck="FALSE"
TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="TRUE"
RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="0"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundation.lib"
OutputFile="..\bin\PocoZip.dll"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories="..\lib"
GenerateDebugInformation="FALSE"
ProgramDatabaseFile=""
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
OptimizeForWindows98="1"
ImportLibrary="..\lib\PocoZip.lib"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Zip"
Filter="">
<Filter
Name="Header Files"
Filter="">
<File
RelativePath=".\include\Poco\Zip\AutoDetectStream.h">
</File>
<File
RelativePath=".\include\Poco\Zip\Compress.h">
</File>
<File
RelativePath=".\include\Poco\Zip\Decompress.h">
</File>
<File
RelativePath=".\include\Poco\Zip\ParseCallback.h">
</File>
<File
RelativePath=".\include\Poco\Zip\PartialStream.h">
</File>
<File
RelativePath=".\include\Poco\Zip\SkipCallback.h">
</File>
<File
RelativePath=".\include\Poco\Zip\Zip.h">
</File>
<File
RelativePath=".\include\Poco\Zip\ZipArchive.h">
</File>
<File
RelativePath=".\include\Poco\Zip\ZipArchiveInfo.h">
</File>
<File
RelativePath=".\include\Poco\Zip\ZipCommon.h">
</File>
<File
RelativePath=".\include\Poco\Zip\ZipDataInfo.h">
</File>
<File
RelativePath=".\include\Poco\Zip\ZipException.h">
</File>
<File
RelativePath=".\include\Poco\Zip\ZipFileInfo.h">
</File>
<File
RelativePath=".\include\Poco\Zip\ZipLocalFileHeader.h">
</File>
<File
RelativePath=".\include\Poco\Zip\ZipStream.h">
</File>
<File
RelativePath=".\include\Poco\Zip\ZipUtil.h">
</File>
</Filter>
<Filter
Name="Source Files"
Filter="">
<File
RelativePath=".\src\AutoDetectStream.cpp">
</File>
<File
RelativePath=".\src\Compress.cpp">
</File>
<File
RelativePath=".\src\Decompress.cpp">
</File>
<File
RelativePath=".\src\ParseCallback.cpp">
</File>
<File
RelativePath=".\src\PartialStream.cpp">
</File>
<File
RelativePath=".\src\SkipCallback.cpp">
</File>
<File
RelativePath=".\src\ZipArchive.cpp">
</File>
<File
RelativePath=".\src\ZipArchiveInfo.cpp">
</File>
<File
RelativePath=".\src\ZipCommon.cpp">
</File>
<File
RelativePath=".\src\ZipDataInfo.cpp">
</File>
<File
RelativePath=".\src\ZipException.cpp">
</File>
<File
RelativePath=".\src\ZipFileInfo.cpp">
</File>
<File
RelativePath=".\src\ZipLocalFileHeader.cpp">
</File>
<File
RelativePath=".\src\ZipStream.cpp">
</File>
<File
RelativePath=".\src\ZipUtil.cpp">
</File>
</Filter>
</Filter>
<Filter
Name="Manipulation"
Filter="">
<Filter
Name="Header Files"
Filter="">
<File
RelativePath=".\include\Poco\Zip\Add.h">
</File>
<File
RelativePath=".\include\Poco\Zip\Delete.h">
</File>
<File
RelativePath=".\include\Poco\Zip\Keep.h">
</File>
<File
RelativePath=".\include\Poco\Zip\Rename.h">
</File>
<File
RelativePath=".\include\Poco\Zip\Replace.h">
</File>
<File
RelativePath=".\include\Poco\Zip\ZipManipulator.h">
</File>
<File
RelativePath=".\include\Poco\Zip\ZipOperation.h">
</File>
</Filter>
<Filter
Name="Source Files"
Filter="">
<File
RelativePath=".\src\Add.cpp">
</File>
<File
RelativePath=".\src\Delete.cpp">
</File>
<File
RelativePath=".\src\Keep.cpp">
</File>
<File
RelativePath=".\src\Rename.cpp">
</File>
<File
RelativePath=".\src\Replace.cpp">
</File>
<File
RelativePath=".\src\ZipManipulator.cpp">
</File>
<File
RelativePath=".\src\ZipOperation.cpp">
</File>
</Filter>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

28
Zip/Zip_VS80.sln Normal file
View File

@ -0,0 +1,28 @@
Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Zip", "Zip_VS80.vcproj", "{4AC75EAD-BFCF-41E6-AB1F-0DA203CC7C61}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestSuite", "testsuite\TestSuite_VS80.vcproj", "{9665FC3C-DB71-4C6C-AAEE-AAFD73CB31E7}"
ProjectSection(ProjectDependencies) = postProject
{4AC75EAD-BFCF-41E6-AB1F-0DA203CC7C61} = {4AC75EAD-BFCF-41E6-AB1F-0DA203CC7C61}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
debug_shared|Win32 = debug_shared|Win32
release_shared|Win32 = release_shared|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4AC75EAD-BFCF-41E6-AB1F-0DA203CC7C61}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
{4AC75EAD-BFCF-41E6-AB1F-0DA203CC7C61}.debug_shared|Win32.Build.0 = debug_shared|Win32
{4AC75EAD-BFCF-41E6-AB1F-0DA203CC7C61}.release_shared|Win32.ActiveCfg = release_shared|Win32
{4AC75EAD-BFCF-41E6-AB1F-0DA203CC7C61}.release_shared|Win32.Build.0 = release_shared|Win32
{9665FC3C-DB71-4C6C-AAEE-AAFD73CB31E7}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
{9665FC3C-DB71-4C6C-AAEE-AAFD73CB31E7}.debug_shared|Win32.Build.0 = debug_shared|Win32
{9665FC3C-DB71-4C6C-AAEE-AAFD73CB31E7}.release_shared|Win32.ActiveCfg = release_shared|Win32
{9665FC3C-DB71-4C6C-AAEE-AAFD73CB31E7}.release_shared|Win32.Build.0 = release_shared|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

413
Zip/Zip_VS80.vcproj Normal file
View File

@ -0,0 +1,413 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Name="Zip"
ProjectGUID="{4AC75EAD-BFCF-41E6-AB1F-0DA203CC7C61}"
RootNamespace="Zip"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared"
ConfigurationType="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".\include;..\Foundation\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;POCO_DLL;Zip_EXPORTS"
StringPooling="true"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
BufferSecurityCheck="true"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
CompileAs="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundationd.lib"
OutputFile="..\bin\PocoZipd.dll"
LinkIncremental="2"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="..\lib"
GenerateDebugInformation="true"
ProgramDatabaseFile="..\bin\PocoZipd.pdb"
SubSystem="1"
OptimizeForWindows98="1"
ImportLibrary="..\lib\PocoZipd.lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="release_shared|Win32"
OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared"
ConfigurationType="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="4"
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories=".\include;..\Foundation\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;POCO_DLL;Zip_EXPORTS"
GeneratePreprocessedFile="0"
KeepComments="false"
StringPooling="true"
RuntimeLibrary="2"
BufferSecurityCheck="false"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="0"
CompileAs="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundation.lib"
OutputFile="..\bin\PocoZip.dll"
LinkIncremental="1"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="..\lib"
GenerateDebugInformation="false"
ProgramDatabaseFile=""
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
OptimizeForWindows98="1"
ImportLibrary="..\lib\PocoZip.lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Zip"
>
<Filter
Name="Header Files"
>
<File
RelativePath=".\include\Poco\Zip\AutoDetectStream.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\Compress.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\Decompress.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\ParseCallback.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\PartialStream.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\SkipCallback.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\Zip.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\ZipArchive.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\ZipArchiveInfo.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\ZipCommon.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\ZipDataInfo.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\ZipException.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\ZipFileInfo.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\ZipLocalFileHeader.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\ZipStream.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\ZipUtil.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\AutoDetectStream.cpp"
>
</File>
<File
RelativePath=".\src\Compress.cpp"
>
</File>
<File
RelativePath=".\src\Decompress.cpp"
>
</File>
<File
RelativePath=".\src\ParseCallback.cpp"
>
</File>
<File
RelativePath=".\src\PartialStream.cpp"
>
</File>
<File
RelativePath=".\src\SkipCallback.cpp"
>
</File>
<File
RelativePath=".\src\ZipArchive.cpp"
>
</File>
<File
RelativePath=".\src\ZipArchiveInfo.cpp"
>
</File>
<File
RelativePath=".\src\ZipCommon.cpp"
>
</File>
<File
RelativePath=".\src\ZipDataInfo.cpp"
>
</File>
<File
RelativePath=".\src\ZipException.cpp"
>
</File>
<File
RelativePath=".\src\ZipFileInfo.cpp"
>
</File>
<File
RelativePath=".\src\ZipLocalFileHeader.cpp"
>
</File>
<File
RelativePath=".\src\ZipStream.cpp"
>
</File>
<File
RelativePath=".\src\ZipUtil.cpp"
>
</File>
</Filter>
</Filter>
<Filter
Name="Manipulation"
>
<Filter
Name="Header Files"
>
<File
RelativePath=".\include\Poco\Zip\Add.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\Delete.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\Keep.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\Rename.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\Replace.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\ZipManipulator.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\ZipOperation.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\Add.cpp"
>
</File>
<File
RelativePath=".\src\Delete.cpp"
>
</File>
<File
RelativePath=".\src\Keep.cpp"
>
</File>
<File
RelativePath=".\src\Rename.cpp"
>
</File>
<File
RelativePath=".\src\Replace.cpp"
>
</File>
<File
RelativePath=".\src\ZipManipulator.cpp"
>
</File>
<File
RelativePath=".\src\ZipOperation.cpp"
>
</File>
</Filter>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

28
Zip/Zip_vs90.sln Normal file
View File

@ -0,0 +1,28 @@
Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Zip", "Zip_vs90.vcproj", "{4AC75EAD-BFCF-41E6-AB1F-0DA203CC7C61}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestSuite", "testsuite\TestSuite_vs90.vcproj", "{9665FC3C-DB71-4C6C-AAEE-AAFD73CB31E7}"
ProjectSection(ProjectDependencies) = postProject
{4AC75EAD-BFCF-41E6-AB1F-0DA203CC7C61} = {4AC75EAD-BFCF-41E6-AB1F-0DA203CC7C61}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
debug_shared|Win32 = debug_shared|Win32
release_shared|Win32 = release_shared|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4AC75EAD-BFCF-41E6-AB1F-0DA203CC7C61}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
{4AC75EAD-BFCF-41E6-AB1F-0DA203CC7C61}.debug_shared|Win32.Build.0 = debug_shared|Win32
{4AC75EAD-BFCF-41E6-AB1F-0DA203CC7C61}.release_shared|Win32.ActiveCfg = release_shared|Win32
{4AC75EAD-BFCF-41E6-AB1F-0DA203CC7C61}.release_shared|Win32.Build.0 = release_shared|Win32
{9665FC3C-DB71-4C6C-AAEE-AAFD73CB31E7}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
{9665FC3C-DB71-4C6C-AAEE-AAFD73CB31E7}.debug_shared|Win32.Build.0 = debug_shared|Win32
{9665FC3C-DB71-4C6C-AAEE-AAFD73CB31E7}.release_shared|Win32.ActiveCfg = release_shared|Win32
{9665FC3C-DB71-4C6C-AAEE-AAFD73CB31E7}.release_shared|Win32.Build.0 = release_shared|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

413
Zip/Zip_vs90.vcproj Normal file
View File

@ -0,0 +1,413 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="Zip"
ProjectGUID="{4AC75EAD-BFCF-41E6-AB1F-0DA203CC7C61}"
RootNamespace="Zip"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared"
ConfigurationType="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".\include;..\Foundation\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;POCO_DLL;Zip_EXPORTS"
StringPooling="true"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
BufferSecurityCheck="true"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="4"
CompileAs="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundationd.lib"
OutputFile="..\bin\PocoZipd.dll"
LinkIncremental="2"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="..\lib"
GenerateDebugInformation="true"
ProgramDatabaseFile="..\bin\PocoZipd.pdb"
SubSystem="1"
OptimizeForWindows98="0"
ImportLibrary="..\lib\PocoZipd.lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="release_shared|Win32"
OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared"
ConfigurationType="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="4"
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories=".\include;..\Foundation\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;POCO_DLL;Zip_EXPORTS"
GeneratePreprocessedFile="0"
KeepComments="false"
StringPooling="true"
RuntimeLibrary="2"
BufferSecurityCheck="false"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="0"
CompileAs="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundation.lib"
OutputFile="..\bin\PocoZip.dll"
LinkIncremental="1"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="..\lib"
GenerateDebugInformation="false"
ProgramDatabaseFile=""
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
OptimizeForWindows98="0"
ImportLibrary="..\lib\PocoZip.lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Zip"
>
<Filter
Name="Header Files"
>
<File
RelativePath=".\include\Poco\Zip\AutoDetectStream.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\Compress.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\Decompress.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\ParseCallback.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\PartialStream.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\SkipCallback.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\Zip.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\ZipArchive.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\ZipArchiveInfo.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\ZipCommon.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\ZipDataInfo.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\ZipException.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\ZipFileInfo.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\ZipLocalFileHeader.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\ZipStream.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\ZipUtil.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\AutoDetectStream.cpp"
>
</File>
<File
RelativePath=".\src\Compress.cpp"
>
</File>
<File
RelativePath=".\src\Decompress.cpp"
>
</File>
<File
RelativePath=".\src\ParseCallback.cpp"
>
</File>
<File
RelativePath=".\src\PartialStream.cpp"
>
</File>
<File
RelativePath=".\src\SkipCallback.cpp"
>
</File>
<File
RelativePath=".\src\ZipArchive.cpp"
>
</File>
<File
RelativePath=".\src\ZipArchiveInfo.cpp"
>
</File>
<File
RelativePath=".\src\ZipCommon.cpp"
>
</File>
<File
RelativePath=".\src\ZipDataInfo.cpp"
>
</File>
<File
RelativePath=".\src\ZipException.cpp"
>
</File>
<File
RelativePath=".\src\ZipFileInfo.cpp"
>
</File>
<File
RelativePath=".\src\ZipLocalFileHeader.cpp"
>
</File>
<File
RelativePath=".\src\ZipStream.cpp"
>
</File>
<File
RelativePath=".\src\ZipUtil.cpp"
>
</File>
</Filter>
</Filter>
<Filter
Name="Manipulation"
>
<Filter
Name="Header Files"
>
<File
RelativePath=".\include\Poco\Zip\Add.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\Delete.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\Keep.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\Rename.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\Replace.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\ZipManipulator.h"
>
</File>
<File
RelativePath=".\include\Poco\Zip\ZipOperation.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\Add.cpp"
>
</File>
<File
RelativePath=".\src\Delete.cpp"
>
</File>
<File
RelativePath=".\src\Keep.cpp"
>
</File>
<File
RelativePath=".\src\Rename.cpp"
>
</File>
<File
RelativePath=".\src\Replace.cpp"
>
</File>
<File
RelativePath=".\src\ZipManipulator.cpp"
>
</File>
<File
RelativePath=".\src\ZipOperation.cpp"
>
</File>
</Filter>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

4
Zip/dependencies Normal file
View File

@ -0,0 +1,4 @@
Foundation
Net
Util
XML

1636
Zip/doc/ZIP Spec.txt Normal file

File diff suppressed because it is too large Load Diff

161
Zip/doc/ZipUserGuide.page Normal file
View File

@ -0,0 +1,161 @@
POCO Zip User Guide
Zip
!!!Introduction
POCO Zip adds support for parsing and creating Zip files. It offers the following features:
* decompress from local files
* decompress from network files while they are downloaded
* compress to local files
* compress directly to a network destination
!!Restrictions
* POCO Zip does not support the DEFLATE64 algorithm.
* encrypted files are not supported
!!!Main Classes
Most users will work with two common classes: <*Compress*> and <*Decompress*>
!!Compress
Compress is a helper class that simplifies creation of Zip files.
Creating a Zip file is a basically a three-step process:
* Create the Compress object: Specify the output stream and define if it is seekable (set to true for local files, to false for network files)
Compress(std::ostream& out, bool seekableOut);
----
* Add entries: either add single files or directory entries
void addFile(std::istream& input,
const Poco::DateTime& lastModifiedAt,
const Poco::Path& fileName,
ZipCommon::CompressionMethod cm = ZipCommon::CM_DEFLATE,
ZipCommon::CompressionLevel cl = ZipCommon::CL_MAXIMUM);
/// Adds a single file to the Zip File. fileName must not be a directory name.
void addFile(const Poco::Path& file,
const Poco::Path& fileName,
ZipCommon::CompressionMethod cm = ZipCommon::CM_DEFLATE,
ZipCommon::CompressionLevel cl = ZipCommon::CL_MAXIMUM);
/// Adds a single file to the Zip File. fileName must not be a directory name. The file must exist physically!
void addDirectory(const Poco::Path& entryName, const Poco::DateTime& lastModifiedAt);
/// Adds a directory entry excluding all children to the Zip file, entryName must not be empty.
void addRecursive(const Poco::Path& entry,
ZipCommon::CompressionLevel cl = ZipCommon::CL_MAXIMUM,
bool excludeRoot = true,
const Poco::Path& name = Poco::Path());
/// Adds a directory entry recursively to the zip file, set excludeRoot to false to exclude the parent directory.
/// The name specifies under which path the entries are added in the Zip file.
----
Note that one must always define a name when adding a file entry, otherwise the compresser can not decide if the file should be added with an absolute or a relative path.
Assume you are adding the file <*c:\\data\\hello.txt*> twice to a Zip:
// MUST use binary!
std::ofstream out("test.zip", std::ios::binary);
Compress c(out, true);
Poco::Path aFile("c:\\data\\hello.txt");
c.addFile(theFile, "hello.txt");
c.addFile(theFile, theFile);
c.close(); // MUST be done to finalize the Zip file
----
A Zip file stores entries internally in UNIX path style. The Zip file created above will contain the following entries:
hello.txt
data/
data/hello.txt
----
The directory entry <*data/*> was automatically added.
When adding directories recursively, the same principle applies. You specify the root directory that should be added and an optional path name where entries are added in the Zip file.
Assume you have the following directory structure:
data/
run1/
result1.txt
run2/
result2.txt
----
The following call will add all subdirectories and all files of data to the Zip but not the root entry <*data*>:
Poco::Path data("data");
data.makeDirectory();
c.addRecursive(data);
----
Or if you want the files to be added under the directory name <*20070401*> (you basically <*rename*> data to 20070401):
Poco::Path data("data");
Poco::Path name("20070401);
data.makeDirectory();
name.makeDirectory();
c.addRecursive(data, ZipCommon::CL_NORMAL, false, name);
----
Note that <*makeDirectory*> does not create a directory, it simply assures that the Path is treated as a directory not as a file.
Also using NORMAL compression instead of MAXIMUM (which is the default) has the benefit of improved performance.
To get notified about the entries that are added during <*addRecursive*> register to the <!EDone!> event of the Compress object:
Poco::FIFOEvent<const ZipLocalFileHeader> EDone;
----
* Closing the Zip file: It is mandatory to manually close Compress objects. This guarantees that the Zip directory is written, thus creating a valid Zip file. It is safe to call <*close*> multiple times, only the first call takes effect.
ZipArchive close();
----
<*close*> returns a ZipArchive which describes all entries inside a Zip file.
!!Decompress
Decompress can be used to decompress all files from a Zip file or to decompress single files only.
!Decompress All
The following sample code shows how all entries can be extracted from a Zip file:
std::ifstream inp("test.zip", std::ios::binary);
poco_assert (inp);
// decompress to current working dir
Decompress dec(inp, Poco::Path());
// if an error happens invoke the ZipTest::onDecompressError method
dec.EError += Poco::Delegate<ZipTest, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string> >(this, &ZipTest::onDecompressError);
dec.decompressAllFiles();
dec.EError -= Poco::Delegate<ZipTest, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string> >(this, &ZipTest::onDecompressError);
----
The onDecompressError method:
void ZipTest::onDecompressError(const void* pSender, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string>& info)
{
// inform user about error
[...]
}
----
Decompressing directly from the net works similar:
Poco::URI uri("http://www.appinf.com/test.zip");
HTTPClientSession session(uri.getHost(), uri.getPort());
HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
session.sendRequest(req);
HTTPResponse res;
std::istream& rs = session.receiveResponse(res);
Decompress dec(rs, Poco::Path());
// if an error happens invoke the ZipTest::onDecompressError method
dec.EError += Poco::Delegate<ZipTest, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string> >(this, &ZipTest::onDecompressError);
dec.decompressAllFiles();
dec.EError -= Poco::Delegate<ZipTest, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string> >(this, &ZipTest::onDecompressError);
----
Furthermore, Decompress supports additional parameters:
Decompress(std::istream& in, const Poco::Path& outputDir, bool flattenDirs = false, bool keepIncompleteFiles = false);
----
If <*flattenDirs*> is set to true no subdirs are extracted, if <*keepIncompleteFiles*> is set to true, corrupt files (i.e. wrong CRC, wrong size on disk) will not be deleted.
!Decompress Single Files
To decompress single files you must first parse a Zip file, and then decompress the file which happens transparently inside the <*ZipInputStream*>:
std::ifstream inp("test.zip", std::ios::binary);
poco_assert (inp);
ZipArchive arch(inp);
ZipArchive::FileHeaders::const_iterator it = arch.findHeader("data/hello.txt");
poco_assert (it != arch.headerEnd());
ZipInputStream zipin (inp, it->second);
std::ostringstream out(std::ios::binary);
Poco::StreamCopier::copyStream(zipin, out);
----
Note that this will only work with local files which allow us to seek inside the file.
Directly extracting single entries from a network file is currently not possible via the Decompress class.

View File

@ -0,0 +1,73 @@
//
// Add.h
//
// $Id: //poco/1.3/Zip/include/Poco/Zip/Add.h#1 $
//
// Library: Zip
// Package: Manipulation
// Module: Add
//
// Definition of the Add class.
//
// 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.
//
#ifndef Zip_Add_INCLUDED
#define Zip_Add_INCLUDED
#include "Poco/Zip/Zip.h"
#include "Poco/Zip/ZipOperation.h"
#include "Poco/Zip/ZipCommon.h"
namespace Poco {
namespace Zip {
class Zip_API Add: public ZipOperation
/// Operation Add adds a new file entry to an existing Zip File
{
public:
Add(const std::string& zipPath, const std::string& localPath, ZipCommon::CompressionMethod cm, ZipCommon::CompressionLevel cl);
/// Creates the Add.
void execute(Compress& c, std::istream& input);
/// Performs the add operation
private:
const std::string _zipPath;
const std::string _localPath;
const ZipCommon::CompressionMethod _cm;
const ZipCommon::CompressionLevel _cl;
};
} } // namespace Poco::Zip
#endif // Zip_Add_INCLUDED

View File

@ -0,0 +1,152 @@
//
// AutoDetectStream.h
//
// $Id: //poco/1.3/Zip/include/Poco/Zip/AutoDetectStream.h#4 $
//
// Library: Zip
// Package: Zip
// Module: AutoDetectStream
//
// Definition of the AutoDetectStream class.
//
// 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.
//
#ifndef Zip_AutoDetectStream_INCLUDED
#define Zip_AutoDetectStream_INCLUDED
#include "Poco/Zip/Zip.h"
#include "Poco/BufferedStreamBuf.h"
#include <istream>
#include <ostream>
namespace Poco {
namespace Zip {
class Zip_API AutoDetectStreamBuf: public Poco::BufferedStreamBuf
/// A AutoDetectStreamBuf is a class that limits one view on an inputstream to a selected view range
{
public:
AutoDetectStreamBuf(std::istream& in, const std::string& prefix, const std::string& postfix, bool reposition, Poco::UInt32 start);
/// Creates the AutoDetectStream.
AutoDetectStreamBuf(std::ostream& out);
/// Creates the AutoDetectStream.
/// If initStream is true the status of the stream will be cleared on the first access, and the stream will be repositioned
/// to position start
~AutoDetectStreamBuf();
/// Destroys the AutoDetectStream.
protected:
int readFromDevice(char* buffer, std::streamsize length);
int writeToDevice(const char* buffer, std::streamsize length);
private:
enum
{
STREAM_BUFFER_SIZE = 1024
};
std::istream* _pIstr;
std::ostream* _pOstr;
bool _eofDetected;
int _matchCnt;
std::string _prefix;
std::string _postfix;
bool _reposition;
Poco::UInt32 _start;
};
class Zip_API AutoDetectIOS: public virtual std::ios
/// The base class for AutoDetectInputStream and AutoDetectOutputStream.
///
/// This class is needed to ensure the correct initialization
/// order of the stream buffer and base classes.
{
public:
AutoDetectIOS(std::istream& istr, const std::string& prefix, const std::string& postfix, bool reposition, Poco::UInt32 start);
/// Creates the basic stream and connects it
/// to the given input stream.
AutoDetectIOS(std::ostream& ostr);
/// Creates the basic stream and connects it
/// to the given output stream.
~AutoDetectIOS();
/// Destroys the stream.
AutoDetectStreamBuf* rdbuf();
/// Returns a pointer to the underlying streambuf.
protected:
AutoDetectStreamBuf _buf;
};
class Zip_API AutoDetectInputStream: public AutoDetectIOS, public std::istream
/// This stream copies all characters read through it
/// to one or multiple output streams.
{
public:
AutoDetectInputStream(std::istream& istr, const std::string& prefix = std::string(), const std::string& postfix = std::string(), bool reposition = false, Poco::UInt32 start = 0);
/// Creates the AutoDetectInputStream and connects it
/// to the given input stream. Bytes read are guaranteed to be in the range [start, end-1]
/// If initStream is true the status of the stream will be cleared on the first access, and the stream will be repositioned
/// to position start
~AutoDetectInputStream();
/// Destroys the AutoDetectInputStream.
};
class Zip_API AutoDetectOutputStream: public AutoDetectIOS, public std::ostream
/// This stream copies all characters written to it
/// to one or multiple output streams.
{
public:
AutoDetectOutputStream(std::ostream& ostr);
/// Creates the AutoDetectOutputStream and connects it
/// to the given input stream. Bytes written are guaranteed to be in the range [start, end-1]
/// If initStream is true the status of the stream will be cleared on the first access, and the stream will be repositioned
/// to position start
~AutoDetectOutputStream();
/// Destroys the AutoDetectOutputStream.
};
} } // namespace Poco::Zip
#endif // Zip_AutoDetectStream_INCLUDED

View File

@ -0,0 +1,112 @@
//
// Compress.h
//
// $Id: //poco/1.3/Zip/include/Poco/Zip/Compress.h#4 $
//
// Library: Zip
// Package: Zip
// Module: Compress
//
// Definition of the Compress class.
//
// 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.
//
#ifndef Zip_Compress_INCLUDED
#define Zip_Compress_INCLUDED
#include "Poco/Zip/Zip.h"
#include "Poco/Zip/ZipArchive.h"
#include "Poco/FIFOEvent.h"
namespace Poco {
namespace Zip {
class Zip_API Compress
/// Compresses a directory or files as zip.
{
public:
Poco::FIFOEvent<const ZipLocalFileHeader> EDone;
Compress(std::ostream& out, bool seekableOut);
/// 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
~Compress();
void addFile(std::istream& input, const Poco::DateTime& lastModifiedAt, const Poco::Path& fileName, ZipCommon::CompressionMethod cm = ZipCommon::CM_DEFLATE, ZipCommon::CompressionLevel cl = ZipCommon::CL_MAXIMUM);
/// Adds a single file to the Zip File. fileName must not be a directory name.
void addFile(const Poco::Path& file, const Poco::Path& fileName, ZipCommon::CompressionMethod cm = ZipCommon::CM_DEFLATE, ZipCommon::CompressionLevel cl = ZipCommon::CL_MAXIMUM);
/// Adds a single file to the Zip File. fileName must not be a directory name. The file must exist physically!
void addDirectory(const Poco::Path& entryName, const Poco::DateTime& lastModifiedAt);
/// Adds a directory entry excluding all children to the Zip file, entryName must not be empty.
void addRecursive(const Poco::Path& entry, ZipCommon::CompressionLevel cl = ZipCommon::CL_MAXIMUM, bool excludeRoot = true, const Poco::Path& name = Poco::Path());
/// Adds a directory entry recursively to the zip file, set excludeRoot to false to exclude the parent directory.
/// If excludeRoot is true you can specify an empty name to add the files as relative files
ZipArchive close();
/// Finalizes the ZipArchive, closes it.
private:
enum
{
COMPRESS_CHUNK_SIZE = 8192
};
Compress(const Compress&);
Compress& operator=(const Compress&);
void addEntry(std::istream& input, const Poco::DateTime& lastModifiedAt, const Poco::Path& fileName, ZipCommon::CompressionMethod cm = ZipCommon::CM_DEFLATE, ZipCommon::CompressionLevel cl = ZipCommon::CL_MAXIMUM);
/// Either adds a file or a single directory entry (excluding subchildren) to the Zip file. the compression level will be ignored
/// for directories.
void addFileRaw(std::istream& in, const ZipLocalFileHeader& hdr, const Poco::Path& fileName);
/// copys an already compressed ZipEntry from in
private:
std::ostream& _out;
bool _seekableOut;
ZipArchive::FileHeaders _files;
ZipArchive::FileInfos _infos;
ZipArchive::DirectoryInfos _dirs;
Poco::UInt32 _offset;
friend class Keep;
friend class Rename;
};
} } // namespace Poco::Zip
#endif // Zip_Compress_INCLUDED

View File

@ -0,0 +1,111 @@
//
// Decompress.h
//
// $Id: //poco/1.3/Zip/include/Poco/Zip/Decompress.h#3 $
//
// Library: Zip
// Package: Zip
// Module: Decompress
//
// Definition of the Decompress class.
//
// 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.
//
#ifndef Zip_Decompress_INCLUDED
#define Zip_Decompress_INCLUDED
#include "Poco/Zip/Zip.h"
#include "Poco/Zip/ParseCallback.h"
#include "Poco/Path.h"
#include "Poco/FIFOEvent.h"
namespace Poco {
namespace Zip {
class ZipArchive;
class Zip_API Decompress: public ParseCallback
/// Decompress extracts files from zip files, can be used to extract single files or all files
{
public:
typedef std::map<std::string, Poco::Path> ZipMapping;
/// Maps key of FileInfo entries to their local decompressed representation
Poco::FIFOEvent<std::pair<const ZipLocalFileHeader, const std::string> > EError;
/// Thrown whenever an error is detected when handling a ZipLocalFileHeader entry. The string contains an error message
Poco::FIFOEvent<std::pair<const ZipLocalFileHeader, const Poco::Path> > EOk;
/// Thrown whenever a file was successfully decompressed
Decompress(std::istream& in, const Poco::Path& outputDir, bool flattenDirs = false, bool keepIncompleteFiles = false);
/// Creates the Decompress. Note that istream must be good and at the very beginning of the file!
/// Calling decompressAllFiles will cause the stream to be in state failed once the zip file is processed.
/// outputDir must be a directory. If it doesn't exist yet, it will be automatically created.
/// If flattenDirs is set to true, the directory structure of the zip file is not recreated.
/// Instead, all files are extracted into one single directory.
~Decompress();
/// Destroys the Decompress.
ZipArchive decompressAllFiles();
/// Decompresses all files stored in the zip File. Can only be called once per Decompress object.
/// Use mapping to retrieve the location of the decompressed files
bool handleZipEntry(std::istream& zipStream, const ZipLocalFileHeader& hdr);
const ZipMapping& mapping() const;
/// A ZipMapping stores as key the full name of the ZipFileInfo/ZipLocalFileHeader and as value the decompressed file
/// If for a ZipFileInfo no mapping exists, there was an error during decompression and the entry is considered to be corrupt
private:
Decompress(const Decompress&);
Decompress& operator=(const Decompress&);
void onOk(const void*, std::pair<const ZipLocalFileHeader, const Poco::Path>& val);
private:
std::istream& _in;
Poco::Path _outDir;
bool _flattenDirs;
bool _keepIncompleteFiles;
ZipMapping _mapping;
};
inline const Decompress::ZipMapping& Decompress::mapping() const
{
return _mapping;
}
} } // namespace Poco::Zip
#endif // Zip_Decompress_INCLUDED

View File

@ -0,0 +1,70 @@
//
// Delete.h
//
// $Id: //poco/1.3/Zip/include/Poco/Zip/Delete.h#1 $
//
// Library: Zip
// Package: Manipulation
// Module: Delete
//
// Definition of the Delete class.
//
// 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.
//
#ifndef Zip_Delete_INCLUDED
#define Zip_Delete_INCLUDED
#include "Poco/Zip/Zip.h"
#include "Poco/Zip/ZipOperation.h"
#include "Poco/Zip/ZipLocalFileHeader.h"
namespace Poco {
namespace Zip {
class Zip_API Delete: public ZipOperation
/// Delete Operation removes an entry from a Zip
{
public:
Delete(const ZipLocalFileHeader& hdr);
/// Creates the Delete.
void execute(Compress& c, std::istream& input);
/// Throws away the ZipEntry
private:
const ZipLocalFileHeader _hdr;
};
} } // namespace Poco::Zip
#endif // Zip_Delete_INCLUDED

View File

@ -0,0 +1,71 @@
//
// Keep.h
//
// $Id: //poco/1.3/Zip/include/Poco/Zip/Keep.h#1 $
//
// Library: Zip
// Package: Manipulation
// Module: Keep
//
// Definition of the Keep class.
//
// 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.
//
#ifndef Zip_Keep_INCLUDED
#define Zip_Keep_INCLUDED
#include "Poco/Zip/Zip.h"
#include "Poco/Zip/ZipOperation.h"
#include "Poco/Zip/ZipLocalFileHeader.h"
namespace Poco {
namespace Zip {
class Zip_API Keep: public ZipOperation
/// Keep simply forwards the compressed data stream from the input ZipArchive
/// to the output zip archive
{
public:
Keep(const ZipLocalFileHeader& hdr);
/// Creates the Keep object.
void execute(Compress& c, std::istream& input);
///Adds a copy of the compressed input file to the ZipArchive
private:
const ZipLocalFileHeader _hdr;
};
} } // namespace Poco::Zip
#endif // Zip_Keep_INCLUDED

View File

@ -0,0 +1,76 @@
//
// ParseCallback.h
//
// $Id: //poco/1.3/Zip/include/Poco/Zip/ParseCallback.h#3 $
//
// Library: Zip
// Package: Zip
// Module: ParseCallback
//
// Definition of the ParseCallback class.
//
// 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.
//
#ifndef Zip_ParseCallback_INCLUDED
#define Zip_ParseCallback_INCLUDED
#include "Poco/Zip/Zip.h"
#include <istream>
namespace Poco {
namespace Zip {
class ZipLocalFileHeader;
class Zip_API ParseCallback
/// Interface for callbacks to handle ZipData
{
public:
ParseCallback();
/// Creates the ParseCallback.
virtual ~ParseCallback();
/// Destroys the ParseCallback.
virtual bool handleZipEntry(std::istream& zipStream, const ZipLocalFileHeader& hdr) = 0;
/// Handles parsing of the data of a single Zip Entry. zipStream is guaranteed to be at the very first data byte.
/// Note that a callback class SHOULD consume all data inside a zip file, ie. after
/// processing the next 4 bytes point the next ZipLocalFileHeader or the ZipDirectory.
/// If it fails to do so, it must return false, otherwise true.
};
} } // namespace Poco::Zip
#endif // Zip_ParseCallback_INCLUDED

View File

@ -0,0 +1,209 @@
//
// PartialStream.h
//
// $Id: //poco/1.3/Zip/include/Poco/Zip/PartialStream.h#3 $
//
// Library: Zip
// Package: Zip
// Module: PartialStream
//
// Definition of the PartialStream class.
//
// 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.
//
#ifndef Zip_PartialStream_INCLUDED
#define Zip_PartialStream_INCLUDED
#include "Poco/Zip/Zip.h"
#include "Poco/BufferedStreamBuf.h"
#include "Poco/Buffer.h"
#include <istream>
#include <ostream>
namespace Poco {
namespace Zip {
class Zip_API PartialStreamBuf: public Poco::BufferedStreamBuf
/// A PartialStreamBuf is a class that limits one view on an inputstream to a selected view range
{
public:
PartialStreamBuf(std::istream& in, std::ios::pos_type start, std::ios::pos_type end, const std::string& prefix, const std::string& postfix, bool initStream);
/// Creates the PartialStream.
/// If initStream is true the status of the stream will be cleared on the first access, and the stream will be repositioned
/// to position start
PartialStreamBuf(std::ostream& out, std::size_t start, std::size_t end, bool initStream);
/// Creates the PartialStream.
/// If initStream is true the status of the stream will be cleared on the first access.
/// start and end acts as offset values for the written content. A start value greater than zero,
/// means that the first bytes are not written but discarded instead,
/// an end value not equal to zero means that the last end bytes are not written!
/// Examples:
/// start = 3; end = 1
/// write("hello", 5) -> "l"
~PartialStreamBuf();
/// Destroys the PartialStream.
void close();
/// Flushes a writing streambuf
Poco::UInt64 bytesWritten() const;
protected:
int readFromDevice(char* buffer, std::streamsize length);
int writeToDevice(const char* buffer, std::streamsize length);
private:
enum
{
STREAM_BUFFER_SIZE = 1024
};
bool _initialized;
std::ios::pos_type _start;
Poco::UInt64 _numBytes;
Poco::UInt64 _bytesWritten;
std::istream* _pIstr;
std::ostream* _pOstr;
std::string _prefix;
std::string _postfix;
std::size_t _ignoreStart;
Poco::Buffer<char> _buffer;
Poco::UInt32 _bufferOffset;
};
inline Poco::UInt64 PartialStreamBuf::bytesWritten() const
{
return _bytesWritten;
}
class Zip_API PartialIOS: public virtual std::ios
/// The base class for PartialInputStream and PartialOutputStream.
///
/// This class is needed to ensure the correct initialization
/// order of the stream buffer and base classes.
{
public:
PartialIOS(std::istream& istr, std::ios::pos_type start, std::ios::pos_type end, const std::string& prefix, const std::string& postfix, bool initStream);
/// Creates the basic stream and connects it
/// to the given input stream.
/// If initStream is true the status of the stream will be cleared on the first access, and the stream will be repositioned
/// to position start
PartialIOS(std::ostream& ostr, std::size_t start, std::size_t end, bool initStream);
/// Creates the basic stream and connects it
/// to the given output stream.
/// If initStream is true the status of the stream will be cleared on the first access.
/// start and end acts as offset values for the written content. A start value greater than zero,
/// means that the first bytes are not written but discarded instead,
/// an end value not equal to zero means that the last end bytes are not written!
/// Examples:
/// start = 3; end = 1
/// write("hello", 5) -> "l"
~PartialIOS();
/// Destroys the stream.
PartialStreamBuf* rdbuf();
/// Returns a pointer to the underlying streambuf.
protected:
PartialStreamBuf _buf;
};
class Zip_API PartialInputStream: public PartialIOS, public std::istream
/// This stream copies all characters read through it
/// to one or multiple output streams.
{
public:
PartialInputStream(std::istream& istr, std::ios::pos_type start, std::ios::pos_type end, bool initStream = true, const std::string& prefix = std::string(), const std::string& postfix = std::string());
/// Creates the PartialInputStream and connects it
/// to the given input stream. Bytes read are guaranteed to be in the range [start, end-1]
/// If initStream is true the status of the stream will be cleared on the first access, and the stream will be repositioned
/// to position start
~PartialInputStream();
/// Destroys the PartialInputStream.
};
class Zip_API PartialOutputStream: public PartialIOS, public std::ostream
/// This stream copies all characters written to it
/// to one or multiple output streams.
{
public:
PartialOutputStream(std::ostream& ostr, std::size_t start, std::size_t end, bool initStream = true);
/// Creates the PartialOutputStream and connects it
/// to the given output stream. Bytes written are guaranteed to be in the range [start, realEnd - end].
/// If initStream is true the status of the stream will be cleared on the first access.
/// start and end acts as offset values for the written content. A start value greater than zero,
/// means that the first bytes are not written but discarded instead,
/// an end value not equal to zero means that the last end bytes are not written!
/// Examples:
/// start = 3; end = 1
/// write("hello", 5) -> "l"
///
/// start = 3; end = 0
/// write("hello", 5) -> "lo"
~PartialOutputStream();
/// Destroys the PartialOutputStream.
void close();
/// must be called for the stream to properly terminate it
Poco::UInt64 bytesWritten() const;
/// Returns the number of bytes actually forwarded to the inner ostream
};
inline void PartialOutputStream::close()
{
flush();
_buf.close();
}
inline Poco::UInt64 PartialOutputStream::bytesWritten() const
{
return _buf.bytesWritten();
}
} } // namespace Poco::Zip
#endif // Zip_PartialStream_INCLUDED

View File

@ -0,0 +1,71 @@
//
// Rename.h
//
// $Id: //poco/1.3/Zip/include/Poco/Zip/Rename.h#1 $
//
// Library: Zip
// Package: Manipulation
// Module: Rename
//
// Definition of the Rename class.
//
// 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.
//
#ifndef Zip_Rename_INCLUDED
#define Zip_Rename_INCLUDED
#include "Poco/Zip/Zip.h"
#include "Poco/Zip/ZipOperation.h"
#include "Poco/Zip/ZipLocalFileHeader.h"
namespace Poco {
namespace Zip {
class Zip_API Rename: public ZipOperation
/// Renames an existing Zip Entry
{
public:
Rename(const ZipLocalFileHeader& hdr, const std::string& newZipEntryName);
/// Creates the Rename.
void execute(Compress& c, std::istream& input);
/// Performs the rename operation
private:
const ZipLocalFileHeader _hdr;
const std::string _newZipEntryName;
};
} } // namespace Poco::Zip
#endif // Zip_Rename_INCLUDED

View File

@ -0,0 +1,72 @@
//
// Replace.h
//
// $Id: //poco/1.3/Zip/include/Poco/Zip/Replace.h#1 $
//
// Library: Zip
// Package: Manipulation
// Module: Replace
//
// Definition of the Replace class.
//
// 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.
//
#ifndef Zip_Replace_INCLUDED
#define Zip_Replace_INCLUDED
#include "Poco/Zip/Zip.h"
#include "Poco/Zip/Add.h"
#include "Poco/Zip/Delete.h"
#include "Poco/Zip/ZipOperation.h"
namespace Poco {
namespace Zip {
class Zip_API Replace: public ZipOperation
/// Operation Replace replaces the content of an existing entry with a new one
{
public:
Replace(const ZipLocalFileHeader& hdr, const std::string& localPath);
/// Creates the Replace.
void execute(Compress& c, std::istream& input);
/// Performs the replace operation
private:
Delete _del;
Add _add;
};
} } // namespace Poco::Zip
#endif // Zip_Replace_INCLUDED

View File

@ -0,0 +1,68 @@
//
// SkipCallback.h
//
// $Id: //poco/1.3/Zip/include/Poco/Zip/SkipCallback.h#3 $
//
// Library: Zip
// Package: Zip
// Module: SkipCallback
//
// Definition of the SkipCallback class.
//
// 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.
//
#ifndef Zip_SkipCallback_INCLUDED
#define Zip_SkipCallback_INCLUDED
#include "Poco/Zip/Zip.h"
#include "Poco/Zip/ParseCallback.h"
namespace Poco {
namespace Zip {
class Zip_API SkipCallback: public ParseCallback
/// A SkipCallback simply skips over the data
{
public:
SkipCallback();
/// Creates the SkipCallback.
virtual ~SkipCallback();
/// Destroys the SkipCallback.
bool handleZipEntry(std::istream& zipStream, const ZipLocalFileHeader& hdr);
};
} } // namespace Poco::Zip
#endif // Zip_SkipCallback_INCLUDED

View File

@ -0,0 +1,92 @@
//
// Zip.h
//
// $Id: //poco/1.3/Zip/include/Poco/Zip/Zip.h#4 $
//
// Library: Zip
// Package: Zip
// Module: Zip
//
// Basic definitions for the Poco Zip library.
// This file must be the first file included by every other Zip
// header file.
//
// 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.
//
#ifndef Zip_Zip_INCLUDED
#define Zip_Zip_INCLUDED
#include "Poco/Foundation.h"
//
// The following block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the Zip_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// Zip_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
//
#if defined(_WIN32) && defined(POCO_DLL)
#if defined(Zip_EXPORTS)
#define Zip_API __declspec(dllexport)
#else
#define Zip_API __declspec(dllimport)
#endif
#endif
#if !defined(Zip_API)
#define Zip_API
#endif
//
// Automatically link Zip library.
//
#if defined(_MSC_VER)
#if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(Zip_EXPORTS)
#if defined(POCO_DLL)
#if defined(_DEBUG)
#pragma comment(lib, "PocoZipd.lib")
#else
#pragma comment(lib, "PocoZip.lib")
#endif
#else
#if defined(_DEBUG)
#pragma comment(lib, "PocoZipmtd.lib")
#else
#pragma comment(lib, "PocoZipmt.lib")
#endif
#endif
#endif
#endif
#endif // Zip_Zip_INCLUDED

View File

@ -0,0 +1,136 @@
//
// ZipArchive.h
//
// $Id: //poco/1.3/Zip/include/Poco/Zip/ZipArchive.h#3 $
//
// Library: Zip
// Package: Zip
// Module: ZipArchive
//
// Definition of the ZipArchive class.
//
// 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.
//
#ifndef Zip_ZipArchive_INCLUDED
#define Zip_ZipArchive_INCLUDED
#include "Poco/Zip/Zip.h"
#include "Poco/Zip/ZipLocalFileHeader.h"
#include "Poco/Zip/ZipFileInfo.h"
#include "Poco/Zip/ZipArchiveInfo.h"
#include <iostream>
#include <map>
namespace Poco {
namespace Zip {
class ParseCallback;
class Compress;
class Zip_API ZipArchive
/// A ZipArchive contains information on the content of a zip file
{
public:
typedef std::map<std::string, ZipLocalFileHeader> FileHeaders;
typedef std::map<std::string, ZipFileInfo> FileInfos;
typedef std::map<Poco::UInt16, ZipArchiveInfo> DirectoryInfos;
ZipArchive(std::istream& in);
/// Creates the ZipArchive from a file. Note that the in stream will be in state failed after the constructor is finished
ZipArchive(std::istream& in, ParseCallback& callback);
/// Creates the ZipArchive from a file or network stream. Note that the in stream will be in state failed after the constructor is finished
~ZipArchive();
/// Destroys the ZipArchive.
FileInfos::const_iterator fileInfoBegin() const;
FileInfos::const_iterator fileInfoEnd() const;
FileHeaders::const_iterator findHeader(const std::string& fileName) const;
FileHeaders::const_iterator headerBegin() const;
FileHeaders::const_iterator headerEnd() const;
private:
void parse(std::istream& in, ParseCallback& pc);
ZipArchive(const FileHeaders& entries, const FileInfos& infos, const DirectoryInfos& dirs );
private:
FileHeaders _entries;
/// Info generated by parsing the data block of the zip file
FileInfos _infos;
/// Info generated by parsing the directory block of the zip file
DirectoryInfos _disks;
/// Stores directory info for all found disks
friend class Compress;
};
inline ZipArchive::FileInfos::const_iterator ZipArchive::fileInfoBegin() const
{
return _infos.begin();
}
inline ZipArchive::FileInfos::const_iterator ZipArchive::fileInfoEnd() const
{
return _infos.end();
}
inline ZipArchive::FileHeaders::const_iterator ZipArchive::findHeader(const std::string& fileName) const
{
return _entries.find(fileName);
}
inline ZipArchive::FileHeaders::const_iterator ZipArchive::headerBegin() const
{
return _entries.begin();
}
inline ZipArchive::FileHeaders::const_iterator ZipArchive::headerEnd() const
{
return _entries.end();
}
} } // namespace Poco::Zip
#endif // Zip_ZipArchive_INCLUDED

View File

@ -0,0 +1,210 @@
//
// ZipArchiveInfo.h
//
// $Id: //poco/1.3/Zip/include/Poco/Zip/ZipArchiveInfo.h#3 $
//
// Library: Zip
// Package: Zip
// Module: ZipArchiveInfo
//
// Definition of the ZipArchiveInfo class.
//
// 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.
//
#ifndef Zip_ZipArchiveInfo_INCLUDED
#define Zip_ZipArchiveInfo_INCLUDED
#include "Poco/Zip/Zip.h"
#include "Poco/Zip/ZipCommon.h"
#include "Poco/Zip/ZipUtil.h"
namespace Poco {
namespace Zip {
class Zip_API ZipArchiveInfo
/// A ZipArchiveInfo stores central directory info
{
public:
static const char HEADER[ZipCommon::HEADER_SIZE];
ZipArchiveInfo();
/// Default constructor, everything set to zero or empty
ZipArchiveInfo(std::istream& in, bool assumeHeaderRead);
/// Creates the ZipArchiveInfo by parsing the input stream.
/// If assumeHeaderRead is true we assume that the first 4 bytes were already read outside.
~ZipArchiveInfo();
/// Destroys the ZipArchiveInfo.
Poco::UInt16 getDiskNumber() const;
/// Get the number of the disk where this header can be found
Poco::UInt16 getFirstDiskForDirectoryHeader() const;
/// Returns the number of the disk that contains the start of the directory header
Poco::UInt16 getNumberOfEntries() const;
/// Returns the number of entries on this disk
Poco::UInt16 getTotalNumberOfEntries() const;
/// Returns the total number of entries on all disks
Poco::UInt32 getCentralDirectorySize() const;
/// Returns the size of the central directory in bytes
std::streamoff getHeaderOffset() const;
/// Returns the offset of the header in relation to the begin of this disk
const std::string& getZipComment() const;
/// Returns the (optional) Zip Comment
void setNumberOfEntries(Poco::UInt16 val);
/// Returns the number of entries on this disk
void setTotalNumberOfEntries(Poco::UInt16 val);
/// Returns the total number of entries on all disks
void setCentralDirectorySize(Poco::UInt32 val);
/// Returns the size of the central directory in bytes
void setHeaderOffset(Poco::UInt32 val);
std::string createHeader() const;
/// Creates a header
private:
void parse(std::istream& inp, bool assumeHeaderRead);
Poco::UInt16 getZipCommentSize() const;
private:
enum
{
HEADER_POS = 0,
NUMBEROFTHISDISK_POS = HEADER_POS + ZipCommon::HEADER_SIZE,
NUMBEROFTHISDISK_SIZE = 2,
NUMBEROFCENTRALDIRDISK_POS = NUMBEROFTHISDISK_POS + NUMBEROFTHISDISK_SIZE,
NUMBEROFCENTRALDIRDISK_SIZE = 2,
NUMENTRIESTHISDISK_POS = NUMBEROFCENTRALDIRDISK_POS + NUMBEROFCENTRALDIRDISK_SIZE,
NUMENTRIESTHISDISK_SIZE = 2,
TOTALNUMENTRIES_POS = NUMENTRIESTHISDISK_POS + NUMENTRIESTHISDISK_SIZE,
TOTALNUMENTRIES_SIZE = 2,
CENTRALDIRSIZE_POS = TOTALNUMENTRIES_POS + TOTALNUMENTRIES_SIZE,
CENTRALDIRSIZE_SIZE = 4,
CENTRALDIRSTARTOFFSET_POS = CENTRALDIRSIZE_POS + CENTRALDIRSIZE_SIZE,
CENTRALDIRSTARTOFFSET_SIZE = 4,
ZIPCOMMENT_LENGTH_POS = CENTRALDIRSTARTOFFSET_POS + CENTRALDIRSTARTOFFSET_SIZE,
ZIPCOMMENT_LENGTH_SIZE = 2,
FULLHEADER_SIZE = 22
};
char _rawInfo[FULLHEADER_SIZE];
std::streamoff _startPos;
std::string _comment;
};
inline Poco::UInt16 ZipArchiveInfo::getDiskNumber() const
{
return ZipUtil::get16BitValue(_rawInfo, NUMBEROFTHISDISK_POS);
}
inline Poco::UInt16 ZipArchiveInfo::getFirstDiskForDirectoryHeader() const
{
return ZipUtil::get16BitValue(_rawInfo, NUMBEROFCENTRALDIRDISK_POS);
}
inline Poco::UInt16 ZipArchiveInfo::getNumberOfEntries() const
{
return ZipUtil::get16BitValue(_rawInfo, NUMENTRIESTHISDISK_POS);
}
inline Poco::UInt16 ZipArchiveInfo::getTotalNumberOfEntries() const
{
return ZipUtil::get16BitValue(_rawInfo, TOTALNUMENTRIES_POS);
}
inline Poco::UInt32 ZipArchiveInfo::getCentralDirectorySize() const
{
return ZipUtil::get32BitValue(_rawInfo, CENTRALDIRSIZE_POS);
}
inline std::streamoff ZipArchiveInfo::getHeaderOffset() const
{
return _startPos;
}
inline Poco::UInt16 ZipArchiveInfo::getZipCommentSize() const
{
return ZipUtil::get16BitValue(_rawInfo, ZIPCOMMENT_LENGTH_POS);
}
inline const std::string& ZipArchiveInfo::getZipComment() const
{
return _comment;
}
inline void ZipArchiveInfo::setNumberOfEntries(Poco::UInt16 val)
{
ZipUtil::set16BitValue(val, _rawInfo, NUMENTRIESTHISDISK_POS);
}
inline void ZipArchiveInfo::setTotalNumberOfEntries(Poco::UInt16 val)
{
ZipUtil::set16BitValue(val, _rawInfo, TOTALNUMENTRIES_POS);
}
inline void ZipArchiveInfo::setCentralDirectorySize(Poco::UInt32 val)
{
ZipUtil::set32BitValue(val, _rawInfo, CENTRALDIRSIZE_POS);
}
inline void ZipArchiveInfo::setHeaderOffset(Poco::UInt32 val)
{
ZipUtil::set32BitValue(val, _rawInfo, CENTRALDIRSTARTOFFSET_POS);
}
} } // namespace Poco::Zip
#endif // Zip_ZipArchiveInfo_INCLUDED

View File

@ -0,0 +1,119 @@
//
// ZipCommon.h
//
// $Id: //poco/1.3/Zip/include/Poco/Zip/ZipCommon.h#3 $
//
// Library: Zip
// Package: Zip
// Module: ZipCommon
//
// Definition of the ZipCommon class.
//
// 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.
//
#ifndef Zip_ZipCommon_INCLUDED
#define Zip_ZipCommon_INCLUDED
#include "Poco/Zip/Zip.h"
namespace Poco {
namespace Zip {
class Zip_API ZipCommon
/// Common enums used in the Zip project
{
public:
enum
{
HEADER_SIZE = 4
};
enum CompressionMethod
{
CM_STORE = 0,
CM_SHRUNK = 1,
CM_FACTOR1 = 2,
CM_FACTOR2 = 3,
CM_FACTOR3 = 4,
CM_FACTOR4 = 5,
CM_IMPLODE = 6,
CM_TOKENIZE= 7,
CM_DEFLATE = 8,
CM_ENHANCEDDEFLATE = 9,
CM_DATECOMPRIMPLODING = 10,
CM_UNUSED = 11
};
enum CompressionLevel
{
CL_NORMAL = 0,
CL_MAXIMUM = 1,
CL_FAST = 2,
CL_SUPERFAST = 3
};
enum HostSystem
{
HS_FAT = 0, // + PKZIPW 2.50 VFAT, NTFS
HS_AMIGA = 1,
HS_VMS = 2,
HS_UNIX = 3,
HS_VM_CMS = 4,
HS_ATARI = 5,
HS_HPFS = 6,
HS_MACINTOSH = 7,
HS_ZSYSTEM = 8,
HS_CP_M = 9,
HS_TOPS20 = 10, // used by pkzip2.5 to indicate ntfs
HS_NTFS = 11,
HS_SMS_QDOS = 12,
HS_ACORN = 13,
HS_VFAT = 14,
HS_MVS = 15,
HS_BEOS = 16,
HS_TANDEM = 17,
HS_UNUSED = 18,
};
enum FileType
{
FT_BINARY= 0,
FT_ASCII = 1
};
static const std::string ILLEGAL_PATH;
};
} } // namespace Poco::Zip
#endif // Zip_ZipCommon_INCLUDED

View File

@ -0,0 +1,160 @@
//
// ZipDataInfo.h
//
// $Id: //poco/1.3/Zip/include/Poco/Zip/ZipDataInfo.h#3 $
//
// Library: Zip
// Package: Zip
// Module: ZipDataInfo
//
// Definition of the ZipDataInfo class.
//
// 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.
//
#ifndef Zip_ZipDataInfo_INCLUDED
#define Zip_ZipDataInfo_INCLUDED
#include "Poco/Zip/Zip.h"
#include "Poco/Zip/ZipCommon.h"
#include "Poco/Zip/ZipUtil.h"
namespace Poco {
namespace Zip {
class Zip_API ZipDataInfo
/// A ZipDataInfo stores a Zip data descriptor
{
public:
static const char HEADER[ZipCommon::HEADER_SIZE];
ZipDataInfo();
/// Creates a header with all fields (except the header field) set to 0
ZipDataInfo(std::istream& in, bool assumeHeaderRead);
/// Creates the ZipDataInfo.
~ZipDataInfo();
/// Destroys the ZipDataInfo.
bool isValid() const;
Poco::UInt32 getCRC32() const;
void setCRC32(Poco::UInt32 crc);
Poco::UInt32 getCompressedSize() const;
void setCompressedSize(Poco::UInt32 size);
Poco::UInt32 getUncompressedSize() const;
void setUncompressedSize(Poco::UInt32 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 = 4,
UNCOMPRESSED_POS = COMPRESSED_POS + COMPRESSED_SIZE,
UNCOMPRESSED_SIZE = 4,
FULLHEADER_SIZE = UNCOMPRESSED_POS + UNCOMPRESSED_SIZE
};
char _rawInfo[FULLHEADER_SIZE];
bool _valid;
};
inline const char* ZipDataInfo::getRawHeader() const
{
return _rawInfo;
}
inline bool ZipDataInfo::isValid() const
{
return _valid;
}
inline Poco::UInt32 ZipDataInfo::getCRC32() const
{
return ZipUtil::get32BitValue(_rawInfo, CRC32_POS);
}
inline void ZipDataInfo::setCRC32(Poco::UInt32 crc)
{
return ZipUtil::set32BitValue(crc, _rawInfo, CRC32_POS);
}
inline Poco::UInt32 ZipDataInfo::getCompressedSize() const
{
return ZipUtil::get32BitValue(_rawInfo, COMPRESSED_POS);
}
inline void ZipDataInfo::setCompressedSize(Poco::UInt32 size)
{
return ZipUtil::set32BitValue(size, _rawInfo, COMPRESSED_POS);
}
inline Poco::UInt32 ZipDataInfo::getUncompressedSize() const
{
return ZipUtil::get32BitValue(_rawInfo, UNCOMPRESSED_POS);
}
inline void ZipDataInfo::setUncompressedSize(Poco::UInt32 size)
{
return ZipUtil::set32BitValue(size, _rawInfo, UNCOMPRESSED_POS);
}
inline Poco::UInt32 ZipDataInfo::getFullHeaderSize()
{
return FULLHEADER_SIZE;
}
} } // namespace Poco::Zip
#endif // Zip_ZipDataInfo_INCLUDED

View File

@ -0,0 +1,58 @@
//
// ZipException.h
//
// $Id: //poco/1.3/Zip/include/Poco/Zip/ZipException.h#4 $
//
// Library: Zip
// Package: Zip
// Module: ZipException
//
// Definition of the ZipException class.
//
// 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.
//
#ifndef Zip_ZipException_INCLUDED
#define Zip_ZipException_INCLUDED
#include "Poco/Zip/Zip.h"
#include "Poco/Exception.h"
namespace Poco {
namespace Zip {
POCO_DECLARE_EXCEPTION(Zip_API, ZipException, Poco::RuntimeException)
POCO_DECLARE_EXCEPTION(Zip_API, ZipManipulationException, ZipException)
} } // namespace Poco::Zip
#endif // Zip_ZipException_INCLUDED

View File

@ -0,0 +1,468 @@
//
// ZipFileInfo.h
//
// $Id: //poco/1.3/Zip/include/Poco/Zip/ZipFileInfo.h#3 $
//
// Library: Zip
// Package: Zip
// Module: ZipFileInfo
//
// Definition of the ZipFileInfo class.
//
// 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.
//
#ifndef Zip_ZipFileInfo_INCLUDED
#define Zip_ZipFileInfo_INCLUDED
#include "Poco/Zip/Zip.h"
#include "Poco/Zip/ZipCommon.h"
#include "Poco/Zip/ZipUtil.h"
namespace Poco {
namespace Zip {
class ZipLocalFileHeader;
class Zip_API ZipFileInfo
/// Stores a Zip directory entry of a file
{
public:
static const char HEADER[ZipCommon::HEADER_SIZE];
ZipFileInfo(const ZipLocalFileHeader& header);
/// Creates a ZipFileInfo from a ZipLocalFileHeader
ZipFileInfo(std::istream& in, bool assumeHeaderRead);
/// Creates the ZipFileInfo by parsing the input stream.
/// If assumeHeaderRead is true we assume that the first 4 bytes were already read outside.
~ZipFileInfo();
/// Destroys the ZipFileInfo.
Poco::UInt32 getRelativeOffsetOfLocalHeader() const;
/// Where on the disk starts the localheader. Combined with the disk number gives the exact location of the header
ZipCommon::CompressionMethod getCompressionMethod() const;
bool isEncrypted() const;
const Poco::DateTime& lastModifiedAt() const;
Poco::UInt32 getCRC() const;
Poco::UInt32 getHeaderSize() const;
/// Returns the total size of the header including filename + other additional fields
Poco::UInt32 getCompressedSize() const;
Poco::UInt32 getUncompressedSize() const;
const std::string& getFileName() const;
bool isFile() const;
bool isDirectory() const;
bool hasExtraField() const;
const std::string& getExtraField() const;
const std::string& getFileComment() const;
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
ZipCommon::HostSystem getHostSystem() const;
Poco::UInt16 getDiskNumberStart() const;
/// The number of the disk on which this file begins (multidisk archives)
ZipCommon::FileType getFileType() const;
/// Binary or ASCII file?
std::string createHeader() const;
void setOffset(Poco::UInt32 val);
private:
void setCRC(Poco::UInt32 val);
void setCompressedSize(Poco::UInt32 val);
void setUncompressedSize(Poco::UInt32 val);
void setCompressionMethod(ZipCommon::CompressionMethod cm);
void setCompressionLevel(ZipCommon::CompressionLevel cl);
void setRequiredVersion(int major, int minor);
void setHostSystem(ZipCommon::HostSystem hs);
void setLastModifiedAt(const Poco::DateTime& dt);
void setEncryption(bool val);
void setFileNameLength(Poco::UInt16 size);
void setFileName(const std::string& str);
void parse(std::istream& in, bool assumeHeaderRead);
void parseDateTime();
Poco::UInt32 getCRCFromHeader() const;
Poco::UInt32 getCompressedSizeFromHeader() const;
Poco::UInt32 getUncompressedSizeFromHeader() const;
Poco::UInt16 getFileNameLength() const;
Poco::UInt16 getExtraFieldLength() const;
Poco::UInt16 getFileCommentLength() const;
Poco::UInt32 getExternalFileAttributes() const;
private:
enum
{
HEADER_POS = 0,
VERSIONMADEBY_POS = HEADER_POS + ZipCommon::HEADER_SIZE,
VERSIONMADEBY_SIZE = 2,
VERSION_NEEDED_POS = VERSIONMADEBY_POS + VERSIONMADEBY_SIZE,
VERSION_NEEDED_SIZE = 2,
GENERAL_PURPOSE_POS = VERSION_NEEDED_POS + VERSION_NEEDED_SIZE,
GENERAL_PURPOSE_SIZE = 2,
COMPR_METHOD_POS = GENERAL_PURPOSE_POS + GENERAL_PURPOSE_SIZE,
COMPR_METHOD_SIZE = 2,
LASTMODFILETIME_POS = COMPR_METHOD_POS + COMPR_METHOD_SIZE,
LASTMODFILETIME_SIZE = 2,
LASTMODFILEDATE_POS = LASTMODFILETIME_POS + LASTMODFILETIME_SIZE,
LASTMODFILEDATE_SIZE = 2,
CRC32_POS = LASTMODFILEDATE_POS + LASTMODFILEDATE_SIZE,
CRC32_SIZE = 4,
COMPRESSED_SIZE_POS = CRC32_POS + CRC32_SIZE,
COMPRESSED_SIZE_SIZE = 4,
UNCOMPRESSED_SIZE_POS = COMPRESSED_SIZE_POS + COMPRESSED_SIZE_SIZE,
UNCOMPRESSED_SIZE_SIZE = 4,
FILENAME_LENGTH_POS = UNCOMPRESSED_SIZE_POS + UNCOMPRESSED_SIZE_SIZE,
FILENAME_LENGTH_SIZE = 2,
EXTRAFIELD_LENGTH_POS = FILENAME_LENGTH_POS + FILENAME_LENGTH_SIZE,
EXTRAFIELD_LENGTH_SIZE = 2,
FILECOMMENT_LENGTH_POS = EXTRAFIELD_LENGTH_POS + EXTRAFIELD_LENGTH_SIZE,
FILECOMMENT_LENGTH_SIZE = 2,
DISKNUMBERSTART_POS = FILECOMMENT_LENGTH_POS + FILECOMMENT_LENGTH_SIZE,
DISKNUMBERSTART_SIZE = 2,
INTERNALFILE_ATTR_POS = DISKNUMBERSTART_POS + DISKNUMBERSTART_SIZE,
INTERNALFILE_ATTR_SIZE = 2,
EXTERNALFILE_ATTR_POS = INTERNALFILE_ATTR_POS + INTERNALFILE_ATTR_SIZE,
EXTERNALFILE_ATTR_SIZE = 4,
RELATIVEOFFSETLOCALHEADER_POS = EXTERNALFILE_ATTR_POS + EXTERNALFILE_ATTR_SIZE,
RELATIVEOFFSETLOCALHEADER_SIZE = 4,
FULLHEADER_SIZE = 46
};
char _rawInfo[FULLHEADER_SIZE];
Poco::UInt32 _crc32;
Poco::UInt32 _compressedSize;
Poco::UInt32 _uncompressedSize;
std::string _fileName;
Poco::DateTime _lastModifiedAt;
std::string _extraField;
std::string _fileComment;
};
inline Poco::UInt32 ZipFileInfo::getRelativeOffsetOfLocalHeader() const
{
return ZipUtil::get32BitValue(_rawInfo, RELATIVEOFFSETLOCALHEADER_POS);
}
inline Poco::UInt32 ZipFileInfo::getCRCFromHeader() const
{
return ZipUtil::get32BitValue(_rawInfo, CRC32_POS);
}
inline Poco::UInt32 ZipFileInfo::getCompressedSizeFromHeader() const
{
return ZipUtil::get32BitValue(_rawInfo, COMPRESSED_SIZE_POS);
}
inline Poco::UInt32 ZipFileInfo::getUncompressedSizeFromHeader() const
{
return ZipUtil::get32BitValue(_rawInfo, UNCOMPRESSED_SIZE_POS);
}
inline void ZipFileInfo::parseDateTime()
{
_lastModifiedAt = ZipUtil::parseDateTime(_rawInfo, LASTMODFILETIME_POS, LASTMODFILEDATE_POS);
}
inline ZipCommon::CompressionMethod ZipFileInfo::getCompressionMethod() const
{
return static_cast<ZipCommon::CompressionMethod>(ZipUtil::get16BitValue(_rawInfo, COMPR_METHOD_POS));
}
inline bool ZipFileInfo::isEncrypted() const
{
// bit 0 indicates encryption
return ((ZipUtil::get16BitValue(_rawInfo, GENERAL_PURPOSE_POS) & 0x0001) != 0);
}
inline const Poco::DateTime& ZipFileInfo::lastModifiedAt() const
{
return _lastModifiedAt;
}
inline Poco::UInt32 ZipFileInfo::getCRC() const
{
return _crc32;
}
inline Poco::UInt32 ZipFileInfo::getCompressedSize() const
{
return _compressedSize;
}
inline Poco::UInt32 ZipFileInfo::getUncompressedSize() const
{
return _uncompressedSize;
}
inline const std::string& ZipFileInfo::getFileName() const
{
return _fileName;
}
inline bool ZipFileInfo::isFile() const
{
return !isDirectory();
}
inline bool ZipFileInfo::isDirectory() const
{
poco_assert_dbg(!_fileName.empty());
return getUncompressedSize() == 0 && getCompressionMethod() == ZipCommon::CM_STORE && _fileName[_fileName.length()-1] == '/';
}
inline Poco::UInt16 ZipFileInfo::getFileNameLength() const
{
return ZipUtil::get16BitValue(_rawInfo, FILENAME_LENGTH_POS);
}
inline Poco::UInt16 ZipFileInfo::getExtraFieldLength() const
{
return ZipUtil::get16BitValue(_rawInfo, EXTRAFIELD_LENGTH_POS);
}
inline bool ZipFileInfo::hasExtraField() const
{
return getExtraFieldLength() > 0;
}
inline const std::string& ZipFileInfo::getExtraField() const
{
return _extraField;
}
inline const std::string& ZipFileInfo::getFileComment() const
{
return _fileComment;
}
inline Poco::UInt16 ZipFileInfo::getFileCommentLength() const
{
return ZipUtil::get16BitValue(_rawInfo, FILECOMMENT_LENGTH_POS);
}
inline void ZipFileInfo::getVersionMadeBy(int& major, int& minor)
{
major = (_rawInfo[VERSIONMADEBY_POS]/10);
minor = (_rawInfo[VERSIONMADEBY_POS]%10);
}
inline void ZipFileInfo::getRequiredVersion(int& major, int& minor)
{
major = (_rawInfo[VERSION_NEEDED_POS]/10);
minor = (_rawInfo[VERSION_NEEDED_POS]%10);
}
inline ZipCommon::HostSystem ZipFileInfo::getHostSystem() const
{
return static_cast<ZipCommon::HostSystem>(_rawInfo[VERSION_NEEDED_POS + 1]);
}
inline Poco::UInt16 ZipFileInfo::getDiskNumberStart() const
{
return ZipUtil::get16BitValue(_rawInfo, DISKNUMBERSTART_POS);
}
inline ZipCommon::FileType ZipFileInfo::getFileType() const
{
return static_cast<ZipCommon::FileType>(_rawInfo[INTERNALFILE_ATTR_POS] & 0x01);
}
inline Poco::UInt32 ZipFileInfo::getExternalFileAttributes() const
{
return ZipUtil::get32BitValue(_rawInfo, EXTERNALFILE_ATTR_POS);
}
inline Poco::UInt32 ZipFileInfo::getHeaderSize() const
{
return FULLHEADER_SIZE + getFileNameLength() + getExtraFieldLength() + getFileCommentLength();
}
inline void ZipFileInfo::setCRC(Poco::UInt32 val)
{
_crc32 = val;
ZipUtil::set32BitValue(val, _rawInfo, CRC32_POS);
}
inline void ZipFileInfo::setOffset(Poco::UInt32 val)
{
ZipUtil::set32BitValue(val, _rawInfo, RELATIVEOFFSETLOCALHEADER_POS);
}
inline void ZipFileInfo::setCompressedSize(Poco::UInt32 val)
{
_compressedSize = val;
ZipUtil::set32BitValue(val, _rawInfo, COMPRESSED_SIZE_POS);
}
inline void ZipFileInfo::setUncompressedSize(Poco::UInt32 val)
{
_uncompressedSize = val;
ZipUtil::set32BitValue(val, _rawInfo, UNCOMPRESSED_SIZE_POS);
}
inline void ZipFileInfo::setCompressionMethod(ZipCommon::CompressionMethod cm)
{
ZipUtil::set16BitValue(static_cast<Poco::UInt16>(cm), _rawInfo, COMPR_METHOD_POS);
}
inline void ZipFileInfo::setCompressionLevel(ZipCommon::CompressionLevel cl)
{
// bit 1 and 2 indicate the level
Poco::UInt16 val = static_cast<Poco::UInt16>(cl);
val <<= 1;
Poco::UInt16 mask = 0xfff9;
_rawInfo[GENERAL_PURPOSE_POS] = ((_rawInfo[GENERAL_PURPOSE_POS] & mask) | val);
}
inline void ZipFileInfo::setFileNameLength(Poco::UInt16 size)
{
ZipUtil::set16BitValue(size, _rawInfo, FILENAME_LENGTH_POS);
}
inline void ZipFileInfo::setHostSystem(ZipCommon::HostSystem hs)
{
_rawInfo[VERSIONMADEBY_POS + 1] = static_cast<char>(hs);
_rawInfo[VERSION_NEEDED_POS + 1] = static_cast<char>(hs);
}
inline void ZipFileInfo::setRequiredVersion(int major, int minor)
{
poco_assert (minor < 10);
poco_assert (major < 24);
Poco::UInt8 val = static_cast<unsigned char>(major)*10+static_cast<unsigned char>(minor);
_rawInfo[VERSIONMADEBY_POS] = static_cast<char>(val);
_rawInfo[VERSION_NEEDED_POS] = static_cast<char>(val);
}
inline void ZipFileInfo::setLastModifiedAt(const Poco::DateTime& dt)
{
_lastModifiedAt = dt;
ZipUtil::setDateTime(dt, _rawInfo, LASTMODFILETIME_POS, LASTMODFILEDATE_POS);
}
inline void ZipFileInfo::setEncryption(bool val)
{
if (val)
_rawInfo[GENERAL_PURPOSE_POS] |= 0x01;
else
_rawInfo[GENERAL_PURPOSE_POS] &= 0xfe;
}
inline void ZipFileInfo::setFileName(const std::string& str)
{
_fileName = str;
setFileNameLength(static_cast<Poco::UInt16>(str.size()));
}
} } // namespace Poco::Zip
#endif // Zip_ZipFileInfo_INCLUDED

View File

@ -0,0 +1,486 @@
//
// ZipLocalFileHeader.h
//
// $Id: //poco/1.3/Zip/include/Poco/Zip/ZipLocalFileHeader.h#4 $
//
// Library: Zip
// Package: Zip
// Module: ZipLocalFileHeader
//
// Definition of the ZipLocalFileHeader class.
//
// 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.
//
#ifndef Zip_ZipLocalFileHeader_INCLUDED
#define Zip_ZipLocalFileHeader_INCLUDED
#include "Poco/Zip/Zip.h"
#include "Poco/Zip/ZipUtil.h"
#include "Poco/Zip/ZipCommon.h"
#include "Poco/DateTime.h"
#include "Poco/Path.h"
#include <iostream>
namespace Poco {
namespace Zip {
class ParseCallback;
class Zip_API ZipLocalFileHeader
/// Stores a Zip local file header
{
public:
static const char HEADER[ZipCommon::HEADER_SIZE];
ZipLocalFileHeader(const Poco::Path& fileName, const Poco::DateTime& lastModifiedAt, ZipCommon::CompressionMethod cm, ZipCommon::CompressionLevel cl);
/// Creates a zip file header from an absoluteFile. fileName is the name of the file in the zip, outputIsSeekable determines if we write
/// CRC and file sizes to the LocalFileHeader or after data compression into a ZipDataInfo
ZipLocalFileHeader(std::istream& inp, bool assumeHeaderRead, ParseCallback& callback);
/// Creates the ZipLocalFileHeader by parsing the input stream.
/// If assumeHeaderRead is true we assume that the first 4 bytes were already read outside.
/// If skipOverDataBlock is true we position the stream after the data block (either at the next FileHeader or the Directory Entry)
virtual ~ZipLocalFileHeader();
/// Destroys the ZipLocalFileHeader.
ZipCommon::HostSystem getHostSystem() const;
int getMajorVersionNumber() const;
int getMinorVersionNumber() const;
void getRequiredVersion(int& major, int& minor);
/// The minimum version required to extract the data
Poco::UInt32 getHeaderSize() const;
/// Returns the total size of the header including filename + extra field size
void setStartPos(std::streamoff start);
/// Sets the start position to start and the end position to start+compressedSize
std::streamoff getStartPos() const;
/// Returns the position of the first byte of the header in the file stream
std::streamoff getEndPos() const;
/// Points past the last byte of the file entry (ie. either the first byte of the next header, or the directory)
std::streamoff getDataStartPos() const;
/// Returns the streamoffset for the very first byte of data. Will be equal to DataEndPos if no data present
std::streamoff getDataEndPos() const;
ZipCommon::CompressionMethod getCompressionMethod() const;
ZipCommon::CompressionLevel getCompressionLevel() const;
/// Returns the compression level used. Only valid when the compression method is CM_DEFLATE
bool isEncrypted() const;
const Poco::DateTime& lastModifiedAt() const;
Poco::UInt32 getCRC() const;
Poco::UInt32 getCompressedSize() const;
Poco::UInt32 getUncompressedSize() const;
void setCRC(Poco::UInt32 val);
void setCompressedSize(Poco::UInt32 val);
void setUncompressedSize(Poco::UInt32 val);
const std::string& getFileName() const;
bool isFile() const;
bool isDirectory() const;
bool hasExtraField() const;
const std::string& getExtraField() const;
bool hasData() const;
bool searchCRCAndSizesAfterData() const;
void setSearchCRCAndSizesAfterData(bool val);
void setFileName(const std::string& fileName, bool isDirectory);
std::string createHeader() const;
/// Creates a header
private:
void parse(std::istream& inp, bool assumeHeaderRead);
void parseDateTime();
void init(const Poco::Path& fileName, ZipCommon::CompressionMethod cm, ZipCommon::CompressionLevel cl);
Poco::UInt16 getFileNameLength() const;
Poco::UInt16 getExtraFieldLength() const;
Poco::UInt32 getCRCFromHeader() const;
Poco::UInt32 getCompressedSizeFromHeader() const;
Poco::UInt32 getUncompressedSizeFromHeader() const;
void setRequiredVersion(int major, int minor);
void setHostSystem(ZipCommon::HostSystem hs);
void setLastModifiedAt(const Poco::DateTime& dt);
void setEncryption(bool val);
void setFileNameLength(Poco::UInt16 size);
void setExtraFieldSize(Poco::UInt16 size);
void setCompressionMethod(ZipCommon::CompressionMethod cm);
void setCompressionLevel(ZipCommon::CompressionLevel cl);
private:
enum
{
HEADER_POS = 0,
VERSION_SIZE = 2,
VERSION_POS = HEADER_POS+ZipCommon::HEADER_SIZE,
GENERAL_PURPOSE_SIZE = 2,
GENERAL_PURPOSE_POS = VERSION_POS + VERSION_SIZE,
COMPR_METHOD_SIZE = 2,
COMPR_METHOD_POS = GENERAL_PURPOSE_POS + GENERAL_PURPOSE_SIZE,
LASTMODEFILETIME_SIZE = 2,
LASTMODEFILETIME_POS = COMPR_METHOD_POS + COMPR_METHOD_SIZE,
LASTMODEFILEDATE_SIZE = 2,
LASTMODEFILEDATE_POS = LASTMODEFILETIME_POS + LASTMODEFILETIME_SIZE,
CRC32_SIZE = 4,
CRC32_POS = LASTMODEFILEDATE_POS + LASTMODEFILEDATE_SIZE,
COMPRESSEDSIZE_SIZE = 4,
COMPRESSEDSIZE_POS = CRC32_POS + CRC32_SIZE,
UNCOMPRESSEDSIZE_SIZE = 4,
UNCOMPRESSEDSIZE_POS = COMPRESSEDSIZE_POS + COMPRESSEDSIZE_SIZE,
FILELENGTH_SIZE = 2,
FILELENGTH_POS = UNCOMPRESSEDSIZE_POS + UNCOMPRESSEDSIZE_SIZE,
EXTRAFIELD_LENGTH = 2,
EXTRAFIELD_POS = FILELENGTH_POS + FILELENGTH_SIZE,
FULLHEADER_SIZE = 30
};
char _rawHeader[FULLHEADER_SIZE];
std::streamoff _startPos;
std::streamoff _endPos;
std::string _fileName;
Poco::DateTime _lastModifiedAt;
std::string _extraField;
Poco::UInt32 _crc32;
Poco::UInt32 _compressedSize;
Poco::UInt32 _uncompressedSize;
};
inline void ZipLocalFileHeader::setFileNameLength(Poco::UInt16 size)
{
ZipUtil::set16BitValue(size, _rawHeader, FILELENGTH_POS);
}
inline void ZipLocalFileHeader::setExtraFieldSize(Poco::UInt16 size)
{
ZipUtil::set16BitValue(size, _rawHeader, EXTRAFIELD_POS);
}
inline ZipCommon::HostSystem ZipLocalFileHeader::getHostSystem() const
{
return static_cast<ZipCommon::HostSystem>(_rawHeader[VERSION_POS + 1]);
}
inline void ZipLocalFileHeader::setHostSystem(ZipCommon::HostSystem hs)
{
_rawHeader[VERSION_POS + 1] = static_cast<char>(hs);
}
inline int ZipLocalFileHeader::getMajorVersionNumber() const
{
return (_rawHeader[VERSION_POS]/10);
}
inline int ZipLocalFileHeader::getMinorVersionNumber() const
{
return (_rawHeader[VERSION_POS]%10);
}
inline void ZipLocalFileHeader::getRequiredVersion(int& major, int& minor)
{
major = getMajorVersionNumber();
minor = getMinorVersionNumber();
}
inline void ZipLocalFileHeader::setRequiredVersion(int major, int minor)
{
poco_assert (minor < 10);
poco_assert (major < 24);
_rawHeader[VERSION_POS] = static_cast<char>(static_cast<unsigned char>(major)*10+static_cast<unsigned char>(minor));
}
inline Poco::UInt16 ZipLocalFileHeader::getFileNameLength() const
{
return ZipUtil::get16BitValue(_rawHeader, FILELENGTH_POS);
}
inline Poco::UInt16 ZipLocalFileHeader::getExtraFieldLength() const
{
return ZipUtil::get16BitValue(_rawHeader, EXTRAFIELD_POS);
}
inline Poco::UInt32 ZipLocalFileHeader::getHeaderSize() const
{
return FULLHEADER_SIZE+getExtraFieldLength()+getFileNameLength();
}
inline std::streamoff ZipLocalFileHeader::getStartPos() const
{
return _startPos;
}
inline void ZipLocalFileHeader::setStartPos(std::streamoff start)
{
_startPos = start;
_endPos = start + getHeaderSize()+getCompressedSize();
}
inline std::streamoff ZipLocalFileHeader::getEndPos() const
{
return _endPos;
}
inline void ZipLocalFileHeader::parseDateTime()
{
_lastModifiedAt = ZipUtil::parseDateTime(_rawHeader, LASTMODEFILETIME_POS, LASTMODEFILEDATE_POS);
}
inline void ZipLocalFileHeader::setLastModifiedAt(const Poco::DateTime& dt)
{
_lastModifiedAt = dt;
ZipUtil::setDateTime(dt, _rawHeader, LASTMODEFILETIME_POS, LASTMODEFILEDATE_POS);
}
inline ZipCommon::CompressionMethod ZipLocalFileHeader::getCompressionMethod() const
{
return static_cast<ZipCommon::CompressionMethod>(ZipUtil::get16BitValue(_rawHeader, COMPR_METHOD_POS));
}
inline ZipCommon::CompressionLevel ZipLocalFileHeader::getCompressionLevel() const
{
// bit 1 and 2 indicate the level
return static_cast<ZipCommon::CompressionLevel>((ZipUtil::get16BitValue(_rawHeader, GENERAL_PURPOSE_POS)>>1) & 0x0003);
}
inline void ZipLocalFileHeader::setCompressionMethod(ZipCommon::CompressionMethod cm)
{
ZipUtil::set16BitValue(static_cast<Poco::UInt16>(cm), _rawHeader, COMPR_METHOD_POS);
}
inline void ZipLocalFileHeader::setCompressionLevel(ZipCommon::CompressionLevel cl)
{
// bit 1 and 2 indicate the level
Poco::UInt16 val = static_cast<Poco::UInt16>(cl);
val <<= 1;
Poco::UInt16 mask = 0xfff9;
_rawHeader[GENERAL_PURPOSE_POS] = ((_rawHeader[GENERAL_PURPOSE_POS] & mask) | val);
}
inline bool ZipLocalFileHeader::isEncrypted() const
{
// bit 0 indicates encryption
return ((ZipUtil::get16BitValue(_rawHeader, GENERAL_PURPOSE_POS) & 0x0001) != 0);
}
inline void ZipLocalFileHeader::setEncryption(bool val)
{
if (val)
_rawHeader[GENERAL_PURPOSE_POS] |= 0x01;
else
_rawHeader[GENERAL_PURPOSE_POS] &= 0xfe;
}
inline void ZipLocalFileHeader::setSearchCRCAndSizesAfterData(bool val)
{
//set bit 3 of general purpose reg
if (val)
_rawHeader[GENERAL_PURPOSE_POS] |= 0x08;
else
_rawHeader[GENERAL_PURPOSE_POS] &= 0xf7;
}
inline const Poco::DateTime& ZipLocalFileHeader::lastModifiedAt() const
{
return _lastModifiedAt;
}
inline Poco::UInt32 ZipLocalFileHeader::getCRC() const
{
return _crc32;
}
inline Poco::UInt32 ZipLocalFileHeader::getCompressedSize() const
{
return _compressedSize;
}
inline Poco::UInt32 ZipLocalFileHeader::getUncompressedSize() const
{
return _uncompressedSize;
}
inline void ZipLocalFileHeader::setCRC(Poco::UInt32 val)
{
_crc32 = val;
ZipUtil::set32BitValue(val, _rawHeader, CRC32_POS);
}
inline void ZipLocalFileHeader::setCompressedSize(Poco::UInt32 val)
{
_compressedSize = val;
ZipUtil::set32BitValue(val, _rawHeader, COMPRESSEDSIZE_POS);
}
inline void ZipLocalFileHeader::setUncompressedSize(Poco::UInt32 val)
{
_uncompressedSize = val;
ZipUtil::set32BitValue(val, _rawHeader, UNCOMPRESSEDSIZE_POS);
}
inline Poco::UInt32 ZipLocalFileHeader::getCRCFromHeader() const
{
return ZipUtil::get32BitValue(_rawHeader, CRC32_POS);
}
inline Poco::UInt32 ZipLocalFileHeader::getCompressedSizeFromHeader() const
{
return ZipUtil::get32BitValue(_rawHeader, COMPRESSEDSIZE_POS);
}
inline Poco::UInt32 ZipLocalFileHeader::getUncompressedSizeFromHeader() const
{
return ZipUtil::get32BitValue(_rawHeader, UNCOMPRESSEDSIZE_POS);
}
inline const std::string& ZipLocalFileHeader::getFileName() const
{
return _fileName;
}
inline bool ZipLocalFileHeader::isFile() const
{
return !isDirectory();
}
inline bool ZipLocalFileHeader::isDirectory() const
{
poco_assert_dbg(!_fileName.empty());
return getUncompressedSize() == 0 && getCompressionMethod() == ZipCommon::CM_STORE && _fileName[_fileName.length()-1] == '/';
}
inline bool ZipLocalFileHeader::hasExtraField() const
{
return getExtraFieldLength() > 0;
}
inline const std::string& ZipLocalFileHeader::getExtraField() const
{
return _extraField;
}
inline bool ZipLocalFileHeader::hasData() const
{
return (getCompressedSize() > 0);
}
inline std::streamoff ZipLocalFileHeader::getDataStartPos() const
{
return getStartPos() + getHeaderSize();
}
inline std::streamoff ZipLocalFileHeader::getDataEndPos() const
{
return getDataStartPos()+getCompressedSize();
}
} } // namespace Poco::Zip
#endif // Zip_ZipLocalFileHeader_INCLUDED

View File

@ -0,0 +1,131 @@
//
// ZipManipulator.h
//
// $Id: //poco/1.3/Zip/include/Poco/Zip/ZipManipulator.h#2 $
//
// Library: Zip
// Package: Manipulation
// Module: ZipManipulator
//
// Definition of the ZipManipulator class.
//
// 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.
//
#ifndef Zip_ZipManipulator_INCLUDED
#define Zip_ZipManipulator_INCLUDED
#include "Poco/Zip/Zip.h"
#include "Poco/Zip/ZipArchive.h"
#include "Poco/Zip/ZipCommon.h"
#include "Poco/Zip/ZipOperation.h"
#include "Poco/FIFOEvent.h"
#include "Poco/SharedPtr.h"
#include <map>
namespace Poco {
namespace Zip {
class ZipArchive;
class Zip_API ZipManipulator
/// ZipManipulator allows to add/remove/update files inside zip files
{
public:
Poco::FIFOEvent<const ZipLocalFileHeader> EDone;
// Fired for each entry once commit is invoked
ZipManipulator(const std::string& zipFile, bool backupOriginalFile);
/// Creates the ZipManipulator.
virtual ~ZipManipulator();
/// Destroys the ZipManipulator.
void deleteFile(const std::string& zipPath);
/// Removes the given file from the Zip archive.
void replaceFile(const std::string& zipPath, const std::string& localPath);
/// Replaces the contents of the file in the archive with the contents
/// from the file given by localPath.
void renameFile(const std::string& zipPath, const std::string& newZipPath);
/// Renames the file in the archive to newZipPath
void addFile(const std::string& zipPath, const std::string& localPath, ZipCommon::CompressionMethod cm = ZipCommon::CM_DEFLATE, ZipCommon::CompressionLevel cl = ZipCommon::CL_MAXIMUM);
/// Adds a file to the zip file.
ZipArchive commit();
/// Commits all changes and re-creates the Zip File with the changes applied.
/// Returns the ZipArchive for the newly created archive
///
/// Changes will be first written to a temporary file,
/// then the originalfile will be either deleted or renamed to .bak,
/// then, the temp file will be renamed to the original zip file name.
const ZipArchive& originalArchive() const;
/// Returns the original archive information
private:
const ZipLocalFileHeader& getForChange(const std::string& zipPath) const;
/// Searches for the entry given by the zipPath.
/// Throws an exception if the entry does not exist
/// or if an entry already exists in the Changeslist
void addOperation(const std::string& zipPath, ZipOperation::Ptr ptrOp);
/// Adds the operation to the changes list. Throws an exception if an
/// entry for the zipPath already exists
void onEDone(const void* pSender, const ZipLocalFileHeader& hdr);
/// Forwards the event to the EDone event
ZipArchive compress(const std::string& outFile);
/// Compresses the new file to outFile
private:
typedef std::map<std::string, ZipOperation::Ptr> Changes;
const std::string _zipFile;
bool _backupOriginalFile;
Changes _changes;
Poco::SharedPtr<ZipArchive> _in;
};
inline const ZipArchive& ZipManipulator::originalArchive() const
{
return *_in;
}
} } // namespace Poco::Zip
#endif // Zip_ZipManipulator_INCLUDED

View File

@ -0,0 +1,78 @@
//
// ZipOperation.h
//
// $Id: //poco/1.3/Zip/include/Poco/Zip/ZipOperation.h#1 $
//
// Library: Zip
// Package: Manipulation
// Module: ZipOperation
//
// Definition of the ZipOperation class.
//
// 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.
//
#ifndef Zip_ZipOperation_INCLUDED
#define Zip_ZipOperation_INCLUDED
#include "Poco/Zip/Zip.h"
#include "Poco/RefCountedObject.h"
#include "Poco/AutoPtr.h"
#include <ostream>
#include <istream>
namespace Poco {
namespace Zip {
class Compress;
class Zip_API ZipOperation: public Poco::RefCountedObject
/// Abstract super class for operations on individual zip entries
{
public:
typedef Poco::AutoPtr<ZipOperation> Ptr;
ZipOperation();
/// Creates the ZipOperation.
virtual void execute(Compress& c, std::istream& input) = 0;
/// Executes the operation
protected:
virtual ~ZipOperation();
/// Destroys the ZipOperation.
};
} } // namespace Poco::Zip
#endif // Zip_ZipOperation_INCLUDED

View File

@ -0,0 +1,171 @@
//
// ZipStream.h
//
// $Id: //poco/1.3/Zip/include/Poco/Zip/ZipStream.h#3 $
//
// Library: Zip
// Package: Zip
// Module: ZipStream
//
// Definition of the ZipStream class.
//
// 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.
//
#ifndef Zip_ZipStream_INCLUDED
#define Zip_ZipStream_INCLUDED
#include "Poco/Zip/Zip.h"
#include "Poco/Zip/PartialStream.h"
#include "Poco/SharedPtr.h"
#include "Poco/BufferedStreamBuf.h"
#include "Poco/Checksum.h"
#include <istream>
#include <ostream>
namespace Poco {
namespace Zip {
class ZipArchive;
class ZipLocalFileHeader;
class Zip_API ZipStreamBuf: public Poco::BufferedStreamBuf
/// ZipStreamBuf is used to decompress single files from a Zip file.
{
public:
ZipStreamBuf(std::istream& istr, const ZipLocalFileHeader& fileEntry, bool reposition);
/// Creates the ZipStreamBuf. Set reposition to false, if you do on-the-fly decompression.
ZipStreamBuf(std::ostream& ostr, ZipLocalFileHeader& fileEntry, bool reposition);
/// Creates the ZipStreamBuf. Set reposition to false, if you do on-the-fly compression.
virtual ~ZipStreamBuf();
/// Destroys the ZipStreamBuf.
void close();
/// Informs a writing outputstream that writing is done for this stream
bool crcValid() const;
/// Call this method once all bytes were read from the input stream to determine if the CRC is valid
protected:
int readFromDevice(char* buffer, std::streamsize length);
int writeToDevice(const char* buffer, std::streamsize length);
private:
enum
{
STREAM_BUFFER_SIZE = 1024
};
typedef Poco::SharedPtr<std::istream> PtrIStream;
typedef Poco::SharedPtr<std::ostream> PtrOStream;
std::istream* _pIstr;
std::ostream* _pOstr;
PtrIStream _ptrBuf;
PtrOStream _ptrOBuf;
PtrIStream _ptrHelper;
Poco::SharedPtr<PartialOutputStream> _ptrOHelper;
Poco::Checksum _crc32;
Poco::UInt32 _expectedCrc32;
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::UInt32 _bytesWritten;
ZipLocalFileHeader* _pHeader;
};
class Zip_API ZipIOS: public virtual std::ios
/// The base class for ZipInputStream and ZipOutputStream.
///
/// This class is needed to ensure the correct initialization
/// order of the stream buffer and base classes.
{
public:
ZipIOS(std::istream& istr, const ZipLocalFileHeader& fileEntry, bool reposition);
/// Creates the basic stream and connects it
/// to the given input stream.
ZipIOS(std::ostream& ostr, ZipLocalFileHeader& fileEntry, bool reposition);
/// Creates the basic stream and connects it
/// to the given output stream.
~ZipIOS();
/// Destroys the stream.
ZipStreamBuf* rdbuf();
/// Returns a pointer to the underlying streambuf.
protected:
ZipStreamBuf _buf;
};
class Zip_API ZipInputStream: public ZipIOS, public std::istream
/// This stream copies all characters read through it
/// to one or multiple output streams.
{
public:
ZipInputStream(std::istream& istr, const ZipLocalFileHeader& fileEntry, bool reposition = true);
/// Creates the ZipInputStream and connects it
/// to the given input stream.
~ZipInputStream();
/// Destroys the ZipInputStream.
bool crcValid() const;
/// Call this method once all bytes were read from the input stream to determine if the CRC is valid
};
class Zip_API ZipOutputStream: public ZipIOS, public std::ostream
/// This stream compresses all characters written through it
/// to one output stream.
{
public:
ZipOutputStream(std::ostream& ostr, ZipLocalFileHeader& fileEntry, bool seekableOutput);
/// Creates the ZipOutputStream and connects it
/// to the given output stream.
~ZipOutputStream();
/// Destroys the ZipOutputStream.
void close();
/// Must be called for ZipOutputStreams!
};
} } // namespace Poco::Zip
#endif // Zip_ZipStream_INCLUDED

View File

@ -0,0 +1,119 @@
//
// ZipUtil.h
//
// $Id: //poco/1.3/Zip/include/Poco/Zip/ZipUtil.h#4 $
//
// Library: Zip
// Package: Zip
// Module: ZipUtil
//
// Definition of the ZipUtil class.
//
// 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.
//
#ifndef Zip_ZipUtil_INCLUDED
#define Zip_ZipUtil_INCLUDED
#include "Poco/Zip/Zip.h"
#include "Poco/Zip/ZipCommon.h"
#include "Poco/DateTime.h"
#include "Poco/Path.h"
namespace Poco {
namespace Zip {
class ZipUtil
/// A utility class used for parsing header information inside of zip files
{
public:
static Poco::UInt16 get16BitValue(const char* pVal, const Poco::UInt32 pos);
static Poco::UInt32 get32BitValue(const 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);
static Poco::DateTime parseDateTime(const char* pVal, const Poco::UInt32 timePos, const Poco::UInt32 datePos);
static void setDateTime(const Poco::DateTime& dt, char* pVal, const Poco::UInt32 timePos, const Poco::UInt32 datePos);
static std::string fakeZLibInitString(ZipCommon::CompressionLevel cl);
static void sync(std::istream& in);
/// Searches the next valid header in the input stream, stops right before it
static void verifyZipEntryFileName(const std::string& zipPath);
/// Verifies that the name of the ZipEntry is a valid path
static std::string validZipEntryFileName(const Poco::Path& entry);
private:
ZipUtil();
~ZipUtil();
ZipUtil(const ZipUtil&);
ZipUtil& operator=(const ZipUtil&);
};
inline Poco::UInt16 ZipUtil::get16BitValue(const char* pVal, const Poco::UInt32 pos)
{
return static_cast<Poco::UInt16>((unsigned char)pVal[pos])+ (static_cast<Poco::UInt16>((unsigned char)pVal[pos+1]) << 8);
}
inline Poco::UInt32 ZipUtil::get32BitValue(const char* pVal, const Poco::UInt32 pos)
{
return static_cast<Poco::UInt32>((unsigned char)pVal[pos])+ (static_cast<Poco::UInt32>((unsigned char)pVal[pos+1]) << 8)+
(static_cast<Poco::UInt32>((unsigned char)pVal[pos+2]) << 16) + (static_cast<Poco::UInt32>((unsigned char)pVal[pos+3]) << 24);
}
inline void ZipUtil::set16BitValue(const Poco::UInt16 val, char* pVal, const Poco::UInt32 pos)
{
pVal[pos] = static_cast<char>(val);
pVal[pos+1] = static_cast<char>(val>>8);
}
inline void ZipUtil::set32BitValue(const Poco::UInt32 val, char* pVal, const Poco::UInt32 pos)
{
pVal[pos] = static_cast<char>(val);
pVal[pos+1] = static_cast<char>(val>>8);
pVal[pos+2] = static_cast<char>(val>>16);
pVal[pos+3] = static_cast<char>(val>>24);
}
} } // namespace Poco::Zip
#endif // Zip_ZipUtil_INCLUDED

13
Zip/samples/Makefile Normal file
View File

@ -0,0 +1,13 @@
#
# Makefile
#
# $Id: //poco/1.3/Zip/samples/Makefile#1 $
#
# Makefile for Poco Util Samples
#
.PHONY: projects
clean all: projects
projects:
$(MAKE) -C unzip $(MAKECMDGOALS)
$(MAKE) -C zip $(MAKECMDGOALS)

View File

@ -0,0 +1,39 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unzip", "unzip\unzip_vs71.vcproj", "{0CFFC7B0-04F4-4A60-B6E4-84D78EDA2C73}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zip", "zip\zip_vs71.vcproj", "{73408DCF-2E65-47AF-BF38-7466DAB8D5CB}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
debug_shared = debug_shared
debug_static = debug_static
release_shared = release_shared
release_static = release_static
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{0CFFC7B0-04F4-4A60-B6E4-84D78EDA2C73}.debug_shared.ActiveCfg = debug_shared|Win32
{0CFFC7B0-04F4-4A60-B6E4-84D78EDA2C73}.debug_shared.Build.0 = debug_shared|Win32
{0CFFC7B0-04F4-4A60-B6E4-84D78EDA2C73}.debug_static.ActiveCfg = debug_shared|Win32
{0CFFC7B0-04F4-4A60-B6E4-84D78EDA2C73}.debug_static.Build.0 = debug_shared|Win32
{0CFFC7B0-04F4-4A60-B6E4-84D78EDA2C73}.release_shared.ActiveCfg = release_shared|Win32
{0CFFC7B0-04F4-4A60-B6E4-84D78EDA2C73}.release_shared.Build.0 = release_shared|Win32
{0CFFC7B0-04F4-4A60-B6E4-84D78EDA2C73}.release_static.ActiveCfg = release_shared|Win32
{0CFFC7B0-04F4-4A60-B6E4-84D78EDA2C73}.release_static.Build.0 = release_shared|Win32
{73408DCF-2E65-47AF-BF38-7466DAB8D5CB}.debug_shared.ActiveCfg = debug_shared|Win32
{73408DCF-2E65-47AF-BF38-7466DAB8D5CB}.debug_shared.Build.0 = debug_shared|Win32
{73408DCF-2E65-47AF-BF38-7466DAB8D5CB}.debug_static.ActiveCfg = debug_shared|Win32
{73408DCF-2E65-47AF-BF38-7466DAB8D5CB}.debug_static.Build.0 = debug_shared|Win32
{73408DCF-2E65-47AF-BF38-7466DAB8D5CB}.release_shared.ActiveCfg = release_shared|Win32
{73408DCF-2E65-47AF-BF38-7466DAB8D5CB}.release_shared.Build.0 = release_shared|Win32
{73408DCF-2E65-47AF-BF38-7466DAB8D5CB}.release_static.ActiveCfg = release_shared|Win32
{73408DCF-2E65-47AF-BF38-7466DAB8D5CB}.release_static.Build.0 = release_shared|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,25 @@
Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zip", "zip\zip_vs80.vcproj", "{73408DCF-2E65-47AF-BF38-7466DAB8D5CB}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unzip", "unzip\unzip_vs80.vcproj", "{0CFFC7B0-04F4-4A60-B6E4-84D78EDA2C73}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
debug_shared|Win32 = debug_shared|Win32
release_shared|Win32 = release_shared|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{73408DCF-2E65-47AF-BF38-7466DAB8D5CB}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
{73408DCF-2E65-47AF-BF38-7466DAB8D5CB}.debug_shared|Win32.Build.0 = debug_shared|Win32
{73408DCF-2E65-47AF-BF38-7466DAB8D5CB}.release_shared|Win32.ActiveCfg = release_shared|Win32
{73408DCF-2E65-47AF-BF38-7466DAB8D5CB}.release_shared|Win32.Build.0 = release_shared|Win32
{0CFFC7B0-04F4-4A60-B6E4-84D78EDA2C73}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
{0CFFC7B0-04F4-4A60-B6E4-84D78EDA2C73}.debug_shared|Win32.Build.0 = debug_shared|Win32
{0CFFC7B0-04F4-4A60-B6E4-84D78EDA2C73}.release_shared|Win32.ActiveCfg = release_shared|Win32
{0CFFC7B0-04F4-4A60-B6E4-84D78EDA2C73}.release_shared|Win32.Build.0 = release_shared|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,25 @@
Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zip", "zip\zip_vs90.vcproj", "{73408DCF-2E65-47AF-BF38-7466DAB8D5CB}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unzip", "unzip\unzip_vs90.vcproj", "{0CFFC7B0-04F4-4A60-B6E4-84D78EDA2C73}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
debug_shared|Win32 = debug_shared|Win32
release_shared|Win32 = release_shared|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{73408DCF-2E65-47AF-BF38-7466DAB8D5CB}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
{73408DCF-2E65-47AF-BF38-7466DAB8D5CB}.debug_shared|Win32.Build.0 = debug_shared|Win32
{73408DCF-2E65-47AF-BF38-7466DAB8D5CB}.release_shared|Win32.ActiveCfg = release_shared|Win32
{73408DCF-2E65-47AF-BF38-7466DAB8D5CB}.release_shared|Win32.Build.0 = release_shared|Win32
{0CFFC7B0-04F4-4A60-B6E4-84D78EDA2C73}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
{0CFFC7B0-04F4-4A60-B6E4-84D78EDA2C73}.debug_shared|Win32.Build.0 = debug_shared|Win32
{0CFFC7B0-04F4-4A60-B6E4-84D78EDA2C73}.release_shared|Win32.ActiveCfg = release_shared|Win32
{0CFFC7B0-04F4-4A60-B6E4-84D78EDA2C73}.release_shared|Win32.Build.0 = release_shared|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,17 @@
#
# Makefile
#
# $Id: //poco/1.3/Zip/samples/unzip/Makefile#1 $
#
# Makefile for Poco SampleServer
#
include $(POCO_BASE)/build/rules/global
objects = unzip
target = unzip
target_version = 1
target_libs = PocoZip PocoUtil PocoXML PocoFoundation
include $(POCO_BASE)/build/rules/exec

View File

@ -0,0 +1,182 @@
//
// unzip.cpp
//
// $Id: //poco/1.3/Zip/samples/unzip/src/unzip.cpp#3 $
//
// This sample demonstrates the Decompress class.
//
// 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.
//
#include "Poco/Util/Application.h"
#include "Poco/Util/Option.h"
#include "Poco/Util/OptionSet.h"
#include "Poco/Util/HelpFormatter.h"
#include "Poco/Util/AbstractConfiguration.h"
#include "Poco/AutoPtr.h"
#include "Poco/Zip/Decompress.h"
#include "Poco/Zip/ZipLocalFileHeader.h"
#include "Poco/Zip/ZipArchive.h"
#include "Poco/Path.h"
#include "Poco/File.h"
#include "Poco/Delegate.h"
#include <iostream>
#include <fstream>
using Poco::Util::Application;
using Poco::Util::Option;
using Poco::Util::OptionSet;
using Poco::Util::HelpFormatter;
using Poco::Util::AbstractConfiguration;
using Poco::Util::OptionCallback;
using Poco::Zip::ZipLocalFileHeader;
using Poco::AutoPtr;
class DecompressHandler
{
public:
DecompressHandler()
{
}
~DecompressHandler()
{
}
void onError(const void*, std::pair<const ZipLocalFileHeader, const std::string>& info)
{
Poco::Util::Application::instance().logger().error("ERR: " + info.second);
}
void onOk(const void*, std::pair<const ZipLocalFileHeader, const Poco::Path>& info)
{
Poco::Util::Application::instance().logger().information("OK: " + info.second.toString(Poco::Path::PATH_UNIX));
}
};
class UnzipApp: public Application
/// This sample demonstrates some of the features of the Util::Application class,
/// such as configuration file handling and command line arguments processing.
///
/// Try zip --help (on Unix platforms) or zip /help (elsewhere) for
/// more information.
{
public:
UnzipApp(): _helpRequested(false)
{
}
protected:
void initialize(Application& self)
{
loadConfiguration(); // load default configuration files, if present
Application::initialize(self);
// add your own initialization code here
}
void uninitialize()
{
// add your own uninitialization code here
Application::uninitialize();
}
void reinitialize(Application& self)
{
Application::reinitialize(self);
// add your own reinitialization code here
}
void defineOptions(OptionSet& options)
{
Application::defineOptions(options);
options.addOption(
Option("help", "h", "display help information on command line arguments")
.required(false)
.repeatable(false)
.callback(OptionCallback<UnzipApp>(this, &UnzipApp::handleHelp)));
options.addOption(
Option("file", "f", "specifies the input zip file")
.required(true)
.repeatable(false)
.argument("filename")
.callback(OptionCallback<UnzipApp>(this, &UnzipApp::handleFile)));
}
void handleHelp(const std::string& name, const std::string& value)
{
_helpRequested = true;
displayHelp();
stopOptionsProcessing();
}
void handleFile(const std::string& name, const std::string& value)
{
_zipFile = value;
}
void displayHelp()
{
HelpFormatter helpFormatter(options());
helpFormatter.setCommand(commandName());
helpFormatter.setUsage("OPTIONS outdir");
helpFormatter.setHeader("A application that demonstrates usage of Poco::Zip::Decompress class.");
helpFormatter.format(std::cout);
}
int main(const std::vector<std::string>& args)
{
if (!_helpRequested)
{
Poco::Path outputDir;
if (!args.empty())
outputDir.parseDirectory(args[0]);
std::ifstream in(_zipFile.c_str(), std::ios::binary);
Poco::Zip::Decompress c(in, outputDir);
DecompressHandler handler;
c.EError += Poco::Delegate<DecompressHandler, std::pair<const ZipLocalFileHeader, const std::string> >(&handler, &DecompressHandler::onError);
c.EOk +=Poco::Delegate<DecompressHandler, std::pair<const ZipLocalFileHeader, const Poco::Path> >(&handler, &DecompressHandler::onOk);
c.decompressAllFiles();
c.EError -= Poco::Delegate<DecompressHandler, std::pair<const ZipLocalFileHeader, const std::string> >(&handler, &DecompressHandler::onError);
c.EOk -=Poco::Delegate<DecompressHandler, std::pair<const ZipLocalFileHeader, const Poco::Path> >(&handler, &DecompressHandler::onOk);
}
return Application::EXIT_OK;
}
private:
bool _helpRequested;
std::string _zipFile;
};
POCO_APP_MAIN(UnzipApp)

View File

@ -0,0 +1,149 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="unzip"
ProjectGUID="{0CFFC7B0-04F4-4A60-B6E4-84D78EDA2C73}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Util\include;..\..\..\Zip\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
BufferSecurityCheck="TRUE"
TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="TRUE"
RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundationd.lib PocoXMLd.lib PocoUtild.lib PocoZipd.lib"
OutputFile="bin/unzipd.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="bin/unzipd.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="release_shared|Win32"
OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="4"
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="TRUE"
FavorSizeOrSpeed="1"
OmitFramePointers="TRUE"
OptimizeForWindowsApplication="TRUE"
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Util\include;..\..\..\Zip\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
StringPooling="TRUE"
RuntimeLibrary="2"
BufferSecurityCheck="FALSE"
TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="TRUE"
RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundation.lib PocoXML.lib PocoUtil.lib PocoZip.lib"
OutputFile="bin/unzip.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="FALSE"
ProgramDatabaseFile=""
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Header Files"
Filter="">
</Filter>
<Filter
Name="Source Files"
Filter="">
<File
RelativePath=".\src\unzip.cpp">
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,213 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Name="unzip"
ProjectGUID="{0CFFC7B0-04F4-4A60-B6E4-84D78EDA2C73}"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
UseOfMFC="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Util\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
BufferSecurityCheck="true"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundationd.lib PocoXMLd.lib PocoUtild.lib PocoZipd.lib"
OutputFile="bin/unzipd.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="true"
ProgramDatabaseFile="bin/unzipd.pdb"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="release_shared|Win32"
OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
UseOfMFC="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="4"
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories="..\..\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Util\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
StringPooling="true"
RuntimeLibrary="2"
BufferSecurityCheck="false"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundation.lib PocoXML.lib PocoUtil.lib PocoZip.lib"
OutputFile="bin/unzip.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="false"
ProgramDatabaseFile=""
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Header Files"
>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\unzip.cpp"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,213 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="unzip"
ProjectGUID="{0CFFC7B0-04F4-4A60-B6E4-84D78EDA2C73}"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
UseOfMFC="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Util\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
BufferSecurityCheck="true"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundationd.lib PocoXMLd.lib PocoUtild.lib PocoZipd.lib"
OutputFile="bin/unzipd.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="true"
ProgramDatabaseFile="bin/unzipd.pdb"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="release_shared|Win32"
OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
UseOfMFC="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="4"
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories="..\..\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Util\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
StringPooling="true"
RuntimeLibrary="2"
BufferSecurityCheck="false"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundation.lib PocoXML.lib PocoUtil.lib PocoZip.lib"
OutputFile="bin/unzip.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="false"
ProgramDatabaseFile=""
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Header Files"
>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\unzip.cpp"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

17
Zip/samples/zip/Makefile Normal file
View File

@ -0,0 +1,17 @@
#
# Makefile
#
# $Id: //poco/1.3/Zip/samples/zip/Makefile#1 $
#
# Makefile for Poco SampleApp
#
include $(POCO_BASE)/build/rules/global
objects = zip
target = zip
target_version = 1
target_libs = PocoZip PocoUtil PocoXML PocoFoundation
include $(POCO_BASE)/build/rules/exec

183
Zip/samples/zip/src/zip.cpp Normal file
View File

@ -0,0 +1,183 @@
//
// zip.cpp
//
// $Id: //poco/1.3/Zip/samples/zip/src/zip.cpp#3 $
//
// This sample demonstrates the Compress class.
//
// 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.
//
#include "Poco/Util/Application.h"
#include "Poco/Util/Option.h"
#include "Poco/Util/OptionSet.h"
#include "Poco/Util/HelpFormatter.h"
#include "Poco/Util/AbstractConfiguration.h"
#include "Poco/AutoPtr.h"
#include "Poco/Zip/Compress.h"
#include "Poco/Path.h"
#include "Poco/File.h"
#include "Poco/Delegate.h"
#include <iostream>
#include <fstream>
using Poco::Util::Application;
using Poco::Util::Option;
using Poco::Util::OptionSet;
using Poco::Util::HelpFormatter;
using Poco::Util::AbstractConfiguration;
using Poco::Util::OptionCallback;
using Poco::AutoPtr;
class ZipApp: public Application
/// This sample demonstrates some of the features of the Util::Application class,
/// such as configuration file handling and command line arguments processing.
///
/// Try zip --help (on Unix platforms) or zip /help (elsewhere) for
/// more information.
{
public:
ZipApp(): _helpRequested(false)
{
}
protected:
void initialize(Application& self)
{
loadConfiguration(); // load default configuration files, if present
Application::initialize(self);
// add your own initialization code here
}
void uninitialize()
{
// add your own uninitialization code here
Application::uninitialize();
}
void reinitialize(Application& self)
{
Application::reinitialize(self);
// add your own reinitialization code here
}
void defineOptions(OptionSet& options)
{
Application::defineOptions(options);
options.addOption(
Option("help", "h", "display help information on command line arguments")
.required(false)
.repeatable(false)
.callback(OptionCallback<ZipApp>(this, &ZipApp::handleHelp)));
options.addOption(
Option("file", "f", "specifies the output zip file")
.required(true)
.repeatable(false)
.argument("filename")
.callback(OptionCallback<ZipApp>(this, &ZipApp::handleFile)));
}
void handleHelp(const std::string& name, const std::string& value)
{
_helpRequested = true;
displayHelp();
stopOptionsProcessing();
}
void handleFile(const std::string& name, const std::string& value)
{
_outFile = value;
}
void displayHelp()
{
HelpFormatter helpFormatter(options());
helpFormatter.setCommand(commandName());
helpFormatter.setUsage("OPTIONS <set of input files>");
helpFormatter.setHeader("A application that demonstrates usage of Poco::Zip::Compress class.");
helpFormatter.format(std::cout);
}
void onDone(const void*, const Poco::Zip::ZipLocalFileHeader& hdr)
{
logger().information("DONE: " + hdr.getFileName());
}
int main(const std::vector<std::string>& args)
{
if (!_helpRequested)
{
if (args.empty())
{
logger().warning("No input files specified for compression");
}
else
{
std::ofstream out(_outFile.c_str(), std::ios::binary);
Poco::Zip::Compress c(out, true);
c.EDone += Poco::Delegate<ZipApp, const Poco::Zip::ZipLocalFileHeader>(this, &ZipApp::onDone);
for (std::vector<std::string>::const_iterator it = args.begin(); it != args.end(); ++it)
{
// no WILDCARD support!
Poco::File aFile(*it);
if (!aFile.exists())
{
logger().error("File not found: " + *it);
}
else
{
Poco::Path anEntry(*it);
if (aFile.isDirectory())
{
anEntry.makeDirectory();
c.addRecursive(anEntry, Poco::Zip::ZipCommon::CL_MAXIMUM, (args.size() != 1)); // add root if we have more than one entry
}
else
{
anEntry.makeFile();
c.addFile(anEntry, anEntry);
}
}
}
c.close();
c.EDone -= Poco::Delegate<ZipApp, const Poco::Zip::ZipLocalFileHeader>(this, &ZipApp::onDone);
}
}
return Application::EXIT_OK;
}
private:
bool _helpRequested;
std::string _outFile;
};
POCO_APP_MAIN(ZipApp)

View File

@ -0,0 +1,145 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="zip"
ProjectGUID="{73408DCF-2E65-47AF-BF38-7466DAB8D5CB}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Util\include;..\..\..\Zip\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
BufferSecurityCheck="TRUE"
TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="TRUE"
RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundationd.lib PocoXMLd.lib PocoUtild.lib PocoZipd.lib"
OutputFile="bin/zipd.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="bin/zipd.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="release_shared|Win32"
OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="4"
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="TRUE"
FavorSizeOrSpeed="1"
OmitFramePointers="TRUE"
OptimizeForWindowsApplication="TRUE"
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Util\include;..\..\..\Zip\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
StringPooling="TRUE"
RuntimeLibrary="2"
BufferSecurityCheck="FALSE"
TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="TRUE"
RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundation.lib PocoXML.lib PocoUtil.lib PocoZip.lib"
OutputFile="bin/zip.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="FALSE"
ProgramDatabaseFile=""
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="">
<File
RelativePath=".\src\zip.cpp">
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,209 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Name="zip"
ProjectGUID="{73408DCF-2E65-47AF-BF38-7466DAB8D5CB}"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
UseOfMFC="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Util\include;..\..\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
BufferSecurityCheck="true"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundationd.lib PocoXMLd.lib PocoUtild.lib PocoZipd.lib"
OutputFile="bin/zipd.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="true"
ProgramDatabaseFile="bin/zipd.pdb"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="release_shared|Win32"
OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
UseOfMFC="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="4"
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories="..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Util\include;..\..\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
StringPooling="true"
RuntimeLibrary="2"
BufferSecurityCheck="false"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundation.lib PocoXML.lib PocoUtil.lib PocoZip.lib"
OutputFile="bin/zip.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="false"
ProgramDatabaseFile=""
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\zip.cpp"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,209 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="zip"
ProjectGUID="{73408DCF-2E65-47AF-BF38-7466DAB8D5CB}"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
UseOfMFC="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Util\include;..\..\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
BufferSecurityCheck="true"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundationd.lib PocoXMLd.lib PocoUtild.lib PocoZipd.lib"
OutputFile="bin/zipd.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="true"
ProgramDatabaseFile="bin/zipd.pdb"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="release_shared|Win32"
OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
UseOfMFC="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="4"
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories="..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Util\include;..\..\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
StringPooling="true"
RuntimeLibrary="2"
BufferSecurityCheck="false"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundation.lib PocoXML.lib PocoUtil.lib PocoZip.lib"
OutputFile="bin/zip.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="false"
ProgramDatabaseFile=""
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\zip.cpp"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

60
Zip/src/Add.cpp Normal file
View File

@ -0,0 +1,60 @@
//
// Add.cpp
//
// $Id: //poco/1.3/Zip/src/Add.cpp#1 $
//
// Library: Zip
// Package: Manipulation
// Module: Add
//
// 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.
//
#include "Poco/Zip/Add.h"
#include "Poco/Zip/Compress.h"
namespace Poco {
namespace Zip {
Add::Add(const std::string& zipPath, const std::string& localPath, ZipCommon::CompressionMethod cm, ZipCommon::CompressionLevel cl):
_zipPath(zipPath),
_localPath(localPath),
_cm(cm),
_cl(cl)
{
}
void Add::execute(Compress& c, std::istream& input)
{
c.addFile(Poco::Path(_localPath), Poco::Path(_zipPath), _cm, _cl);
}
} } // namespace Poco::Zip

View File

@ -0,0 +1,252 @@
//
// AutoDetectStream.cpp
//
// $Id: //poco/1.3/Zip/src/AutoDetectStream.cpp#4 $
//
// Library: Zip
// Package: Zip
// Module: AutoDetectStream
//
// 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.
//
#include "Poco/Zip/AutoDetectStream.h"
#include "Poco/Zip/ZipLocalFileHeader.h"
#include "Poco/Zip/ZipArchiveInfo.h"
#include "Poco/Zip/ZipDataInfo.h"
#include "Poco/Zip/ZipFileInfo.h"
#include "Poco/Exception.h"
#include <cstring>
namespace Poco {
namespace Zip {
AutoDetectStreamBuf::AutoDetectStreamBuf(std::istream& in, const std::string& pre, const std::string& post, bool reposition, Poco::UInt32 start):
Poco::BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::in),
_pIstr(&in),
_pOstr(0),
_eofDetected(false),
_matchCnt(0),
_prefix(pre),
_postfix(post),
_reposition(reposition),
_start(start)
{
}
AutoDetectStreamBuf::AutoDetectStreamBuf(std::ostream& out):
Poco::BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::out),
_pIstr(0),
_pOstr(&out),
_eofDetected(false),
_matchCnt(0),
_prefix(),
_postfix(),
_reposition(false),
_start(0u)
{
}
AutoDetectStreamBuf::~AutoDetectStreamBuf()
{
}
int AutoDetectStreamBuf::readFromDevice(char* buffer, std::streamsize length)
{
poco_assert_dbg(length >= 8);
if (_pIstr == 0 ||length == 0) return -1;
if (_reposition)
{
_pIstr->seekg(_start, std::ios_base::beg);
_reposition = false;
}
if (!_prefix.empty())
{
std::streamsize tmp = (_prefix.size() > length)? length: static_cast<std::streamsize>(_prefix.size());
std::memcpy(buffer, _prefix.c_str(), tmp);
_prefix = _prefix.substr(tmp);
return tmp;
}
if (_eofDetected)
{
if (!_postfix.empty())
{
std::streamsize tmp = (_postfix.size() > length)? length: static_cast<std::streamsize>(_postfix.size());
std::memcpy(buffer, _postfix.c_str(), tmp);
_postfix = _postfix.substr(tmp);
return tmp;
}
else
return -1;
}
if (!_pIstr->good())
return -1;
char byte3('\x00');
std::streamsize tempPos = 0;
static std::istream::int_type eof = std::istream::traits_type::eof();
while (_pIstr->good() && !_pIstr->eof() && (tempPos+4) < length)
{
std::istream::int_type c = _pIstr->get();
if (c != eof)
{
// all zip headers start with the same 2byte prefix
if (_matchCnt<2)
{
if (c == ZipLocalFileHeader::HEADER[_matchCnt])
++_matchCnt;
else
{
// matchcnt was either 0 or 1 the headers have all unique chars -> safe to set to 0
if (_matchCnt == 1)
{
buffer[tempPos++] = ZipLocalFileHeader::HEADER[0];
}
_matchCnt = 0;
buffer[tempPos++] = static_cast<char>(c);
}
}
else
{
//the upper 2 bytes differ: the lower one must be in range 1,3,5,7, the upper must be one larger: 2,4,6,8
if (_matchCnt == 2)
{
if (ZipLocalFileHeader::HEADER[2] == c ||
ZipArchiveInfo::HEADER[2] == c ||
ZipFileInfo::HEADER[2] == c ||
ZipDataInfo::HEADER[2] == c)
{
byte3 = static_cast<char>(c);;
_matchCnt++;
}
else
{
buffer[tempPos++] = ZipLocalFileHeader::HEADER[0];
buffer[tempPos++] = ZipLocalFileHeader::HEADER[1];
buffer[tempPos++] = static_cast<char>(c);
_matchCnt = 0;
}
}
else if (_matchCnt == 3)
{
if (c-1 == byte3)
{
// a match, pushback
_pIstr->putback(c);
_pIstr->putback(byte3);
_pIstr->putback(ZipLocalFileHeader::HEADER[1]);
_pIstr->putback(ZipLocalFileHeader::HEADER[0]);
_eofDetected = true;
return tempPos;
}
else
{
buffer[tempPos++] = ZipLocalFileHeader::HEADER[0];
buffer[tempPos++] = ZipLocalFileHeader::HEADER[1];
buffer[tempPos++] = byte3;
buffer[tempPos++] = c;
_matchCnt = 0; //the headers have all unique chars -> safe to set to 0
}
}
}
}
}
return tempPos;
}
int AutoDetectStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
{
if (_pOstr == 0 || length == 0) return -1;
_pOstr->write(buffer, length);
if (_pOstr->good())
return length;
throw Poco::IOException("Failed to write to output stream");
}
AutoDetectIOS::AutoDetectIOS(std::istream& istr, const std::string& pre, const std::string& post, bool reposition, Poco::UInt32 start):
_buf(istr, pre, post, reposition, start)
{
poco_ios_init(&_buf);
}
AutoDetectIOS::AutoDetectIOS(std::ostream& ostr): _buf(ostr)
{
poco_ios_init(&_buf);
}
AutoDetectIOS::~AutoDetectIOS()
{
}
AutoDetectStreamBuf* AutoDetectIOS::rdbuf()
{
return &_buf;
}
AutoDetectInputStream::AutoDetectInputStream(std::istream& istr, const std::string& pre, const std::string& post, bool reposition, Poco::UInt32 start):
AutoDetectIOS(istr, pre, post, reposition, start),
std::istream(&_buf)
{
}
AutoDetectInputStream::~AutoDetectInputStream()
{
}
AutoDetectOutputStream::AutoDetectOutputStream(std::ostream& ostr):
AutoDetectIOS(ostr),
std::ostream(&_buf)
{
}
AutoDetectOutputStream::~AutoDetectOutputStream()
{
}
} } // namespace Poco::Zip

322
Zip/src/Compress.cpp Normal file
View File

@ -0,0 +1,322 @@
//
// Compress.cpp
//
// $Id: //poco/1.3/Zip/src/Compress.cpp#4 $
//
// Library: Zip
// Package: Zip
// Module: Compress
//
// 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.
//
#include "Poco/Zip/Compress.h"
#include "Poco/Zip/ZipLocalFileHeader.h"
#include "Poco/Zip/ZipStream.h"
#include "Poco/Zip/ZipArchiveInfo.h"
#include "Poco/Zip/ZipDataInfo.h"
#include "Poco/Zip/ZipException.h"
#include "Poco/StreamCopier.h"
#include "Poco/File.h"
#include <fstream>
namespace Poco {
namespace Zip {
Compress::Compress(std::ostream& out, bool seekableOut):
_out(out),
_seekableOut(seekableOut),
_files(),
_infos(),
_dirs(),
_offset(0)
{
}
Compress::~Compress()
{
}
void Compress::addEntry(std::istream& in, const Poco::DateTime& lastModifiedAt, const Poco::Path& fileName, ZipCommon::CompressionMethod cm, ZipCommon::CompressionLevel cl)
{
std::string fn = ZipUtil::validZipEntryFileName(fileName);
if (_files.size() >= 65535)
throw ZipException("Maximum number of entries for a ZIP file reached: 65535");
if (!in.good())
throw ZipException("Invalid input stream");
std::streamoff localHeaderOffset = _offset;
ZipLocalFileHeader hdr(fileName, lastModifiedAt, cm, cl);
hdr.setStartPos(localHeaderOffset);
ZipOutputStream zipOut(_out, hdr, _seekableOut);
Poco::StreamCopier::copyStream(in, zipOut);
zipOut.close();
hdr.setStartPos(localHeaderOffset); // reset again now that compressed Size is known
_offset = hdr.getEndPos();
if (hdr.searchCRCAndSizesAfterData())
_offset += ZipDataInfo::getFullHeaderSize();
_files.insert(std::make_pair(fileName.toString(Poco::Path::PATH_UNIX), hdr));
poco_assert (_out);
ZipFileInfo nfo(hdr);
nfo.setOffset(localHeaderOffset);
_infos.insert(std::make_pair(fileName.toString(Poco::Path::PATH_UNIX), nfo));
EDone.notify(this, hdr);
}
void Compress::addFileRaw(std::istream& in, const ZipLocalFileHeader& h, const Poco::Path& fileName)
{
std::string fn = ZipUtil::validZipEntryFileName(fileName);
//bypass the header of the input stream and point to the first byte of the data payload
in.seekg(h.getDataStartPos(), std::ios_base::beg);
if (_files.size() >= 65535)
throw ZipException("Maximum number of entries for a ZIP file reached: 65535");
if (!in.good())
throw ZipException("Invalid input stream");
std::streamoff localHeaderOffset = _offset;
ZipLocalFileHeader hdr(h);
hdr.setFileName(fn, h.isDirectory());
hdr.setStartPos(localHeaderOffset);
//bypass zipoutputstream
//write the header directly
std::string header = hdr.createHeader();
_out.write(header.c_str(), static_cast<std::streamsize>(header.size()));
// now fwd the payload to _out in chunks of size CHUNKSIZE
Poco::UInt32 totalSize = hdr.getCompressedSize();
if (totalSize > 0)
{
Poco::Buffer<char> buffer(COMPRESS_CHUNK_SIZE);
Poco::UInt32 remaining = totalSize;
while(remaining > 0)
{
if (remaining > COMPRESS_CHUNK_SIZE)
{
in.read(buffer.begin(), COMPRESS_CHUNK_SIZE);
std::streamsize n = in.gcount();
poco_assert_dbg (n == COMPRESS_CHUNK_SIZE);
_out.write(buffer.begin(), n);
remaining -= COMPRESS_CHUNK_SIZE;
}
else
{
in.read(buffer.begin(), remaining);
std::streamsize n = in.gcount();
poco_assert_dbg (n == remaining);
_out.write(buffer.begin(), n);
remaining = 0;
}
}
}
//write optional block afterwards
if (hdr.searchCRCAndSizesAfterData())
{
ZipDataInfo info(in, false);
_out.write(info.getRawHeader(), static_cast<std::streamsize>(info.getFullHeaderSize()));
}
hdr.setStartPos(localHeaderOffset); // reset again now that compressed Size is known
_offset = hdr.getEndPos();
if (hdr.searchCRCAndSizesAfterData())
_offset += ZipDataInfo::getFullHeaderSize();
_files.insert(std::make_pair(fileName.toString(Poco::Path::PATH_UNIX), hdr));
poco_assert (_out);
ZipFileInfo nfo(hdr);
nfo.setOffset(localHeaderOffset);
_infos.insert(std::make_pair(fileName.toString(Poco::Path::PATH_UNIX), nfo));
EDone.notify(this, hdr);
}
void Compress::addFile(std::istream& in, const Poco::DateTime& lastModifiedAt, const Poco::Path& fileName, ZipCommon::CompressionMethod cm, ZipCommon::CompressionLevel cl)
{
if (!fileName.isFile())
throw ZipException("Not a file: "+ fileName.toString());
if (fileName.depth() > 1)
{
addDirectory(fileName.parent(), lastModifiedAt);
}
addEntry(in, lastModifiedAt, fileName, cm, cl);
}
void Compress::addFile(const Poco::Path& file, const Poco::Path& fileName, ZipCommon::CompressionMethod cm, ZipCommon::CompressionLevel cl)
{
Poco::File aFile(file);
Poco::File::FileSize size = aFile.getSize();
if (size < 16)
{
cm = ZipCommon::CM_STORE;
cl = ZipCommon::CL_NORMAL;
}
std::ifstream in(file.toString().c_str(), std::ios::binary);
if (!in.good())
throw ZipException("Invalid input stream for " + aFile.path());
if (fileName.depth() > 1)
{
Poco::File aParent(file.parent());
addDirectory(fileName.parent(), aParent.getLastModified());
}
addFile(in, aFile.getLastModified(), fileName, cm, cl);
}
void Compress::addDirectory(const Poco::Path& entryName, const Poco::DateTime& lastModifiedAt)
{
if (!entryName.isDirectory())
throw ZipException("Not a directory: "+ entryName.toString());
std::string fileStr = entryName.toString(Poco::Path::PATH_UNIX);
if (_files.find(fileStr) != _files.end())
return; // ignore duplicate add
if (_files.size() >= 65535)
throw ZipException("Maximum number of entries for a ZIP file reached: 65535");
if (fileStr == "/")
throw ZipException("Illegal entry name /");
if (fileStr.empty())
throw ZipException("Illegal empty entry name");
if (fileStr.find(ZipCommon::ILLEGAL_PATH) != std::string::npos)
throw ZipException("Illegal entry name " + fileStr + " containing " + ZipCommon::ILLEGAL_PATH);
if (entryName.depth() > 1)
{
addDirectory(entryName.parent(), lastModifiedAt);
}
std::streamoff localHeaderOffset = _offset;
ZipCommon::CompressionMethod cm = ZipCommon::CM_STORE;
ZipCommon::CompressionLevel cl = ZipCommon::CL_NORMAL;
ZipLocalFileHeader hdr(entryName, lastModifiedAt, cm, cl);
hdr.setStartPos(localHeaderOffset);
ZipOutputStream zipOut(_out, hdr, _seekableOut);
zipOut.close();
hdr.setStartPos(localHeaderOffset); // reset again now that compressed Size is known
_offset = hdr.getEndPos();
if (hdr.searchCRCAndSizesAfterData())
_offset += ZipDataInfo::getFullHeaderSize();
_files.insert(std::make_pair(entryName.toString(Poco::Path::PATH_UNIX), hdr));
poco_assert (_out);
ZipFileInfo nfo(hdr);
nfo.setOffset(localHeaderOffset);
_infos.insert(std::make_pair(entryName.toString(Poco::Path::PATH_UNIX), nfo));
EDone.notify(this, hdr);
}
void Compress::addRecursive(const Poco::Path& entry, ZipCommon::CompressionLevel cl, bool excludeRoot, const Poco::Path& name)
{
Poco::File aFile(entry);
if (!aFile.isDirectory())
throw ZipException("Not a directory: "+ entry.toString());
Poco::Path aName(name);
aName.makeDirectory();
if (!excludeRoot)
{
if (aName.depth() == 0)
{
Poco::Path tmp(entry);
tmp.makeAbsolute(); // eliminate ../
aName = Poco::Path(tmp[tmp.depth()-1]);
aName.makeDirectory();
}
addDirectory(aName, aFile.getLastModified());
}
// iterate over children
std::vector<std::string> children;
aFile.list(children);
std::vector<std::string>::const_iterator it = children.begin();
std::vector<std::string>::const_iterator itEnd = children.end();
for (; it != itEnd; ++it)
{
Poco::Path realFile(entry, *it);
Poco::Path renamedFile(aName, *it);
Poco::File aFile(realFile);
if (aFile.isDirectory())
{
realFile.makeDirectory();
renamedFile.makeDirectory();
addRecursive(realFile, cl, false, renamedFile);
}
else
{
realFile.makeFile();
renamedFile.makeFile();
addFile(realFile, renamedFile, ZipCommon::CM_DEFLATE, cl);
}
}
}
ZipArchive Compress::close()
{
if (!_dirs.empty())
return ZipArchive(_files, _infos, _dirs);
poco_assert (_infos.size() == _files.size());
poco_assert (_files.size() < 65536);
Poco::UInt32 centralDirStart = _offset;
Poco::UInt32 centralDirSize = 0;
// write all infos
ZipArchive::FileInfos::const_iterator it = _infos.begin();
ZipArchive::FileInfos::const_iterator itEnd = _infos.end();
for (; it != itEnd; ++it)
{
const ZipFileInfo& nfo = it->second;
std::string info(nfo.createHeader());
_out.write(info.c_str(), static_cast<std::streamsize>(info.size()));
Poco::UInt32 entrySize = static_cast<Poco::UInt32>(info.size());
centralDirSize += entrySize;
_offset += entrySize;
}
poco_assert (_out);
Poco::UInt16 numEntries = static_cast<Poco::UInt16>(_infos.size());
ZipArchiveInfo central;
central.setCentralDirectorySize(centralDirSize);
central.setNumberOfEntries(numEntries);
central.setTotalNumberOfEntries(numEntries);
central.setHeaderOffset(centralDirStart);
std::string centr(central.createHeader());
_out.write(centr.c_str(), static_cast<std::streamsize>(centr.size()));
_out.flush();
_dirs.insert(std::make_pair(0, central));
return ZipArchive(_files, _infos, _dirs);
}
} } // namespace Poco::Zip

192
Zip/src/Decompress.cpp Normal file
View File

@ -0,0 +1,192 @@
//
// Decompress.cpp
//
// $Id: //poco/1.3/Zip/src/Decompress.cpp#4 $
//
// Library: Zip
// Package: Zip
// Module: Decompress
//
// 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.
//
#include "Poco/Zip/Decompress.h"
#include "Poco/Zip/ZipLocalFileHeader.h"
#include "Poco/Zip/ZipArchive.h"
#include "Poco/Zip/ZipStream.h"
#include "Poco/Zip/ZipException.h"
#include "Poco/File.h"
#include "Poco/Exception.h"
#include "Poco/StreamCopier.h"
#include "Poco/Delegate.h"
#include <fstream>
namespace Poco {
namespace Zip {
Decompress::Decompress(std::istream& in, const Poco::Path& outputDir, bool flattenDirs, bool keepIncompleteFiles):
_in(in),
_outDir(outputDir),
_flattenDirs(flattenDirs),
_keepIncompleteFiles(keepIncompleteFiles),
_mapping()
{
_outDir.makeAbsolute();
poco_assert (_in.good());
Poco::File tmp(_outDir);
if (!tmp.exists())
{
tmp.createDirectories();
}
if (!tmp.isDirectory())
throw Poco::IOException("Failed to create/open directory: " + _outDir.toString());
EOk += Poco::Delegate<Decompress, std::pair<const ZipLocalFileHeader, const Poco::Path> >(this, &Decompress::onOk);
}
Decompress::~Decompress()
{
EOk -= Poco::Delegate<Decompress, std::pair<const ZipLocalFileHeader, const Poco::Path> >(this, &Decompress::onOk);
}
ZipArchive Decompress::decompressAllFiles()
{
poco_assert (_mapping.empty());
ZipArchive arch(_in, *this);
return arch;
}
bool Decompress::handleZipEntry(std::istream& zipStream, const ZipLocalFileHeader& hdr)
{
if (hdr.isDirectory())
{
// directory have 0 size, nth to read
if (!_flattenDirs)
{
std::string dirName = hdr.getFileName();
if (dirName.find(ZipCommon::ILLEGAL_PATH) != std::string::npos)
throw ZipException("Illegal entry name " + dirName + " containing " + ZipCommon::ILLEGAL_PATH);
Poco::Path dir(dirName);
dir.makeDirectory();
Poco::File aFile(dir);
aFile.createDirectories();
}
return true;
}
try
{
std::string fileName = hdr.getFileName();
if (_flattenDirs)
{
// remove path info
Poco::Path p(fileName);
p.makeFile();
fileName = p.getFileName();
}
if (fileName.find(ZipCommon::ILLEGAL_PATH) != std::string::npos)
throw ZipException("Illegal entry name " + fileName + " containing " + ZipCommon::ILLEGAL_PATH);
Poco::Path file(fileName);
file.makeFile();
Poco::Path dest(_outDir, file);
dest.makeFile();
if (dest.depth() > 0)
{
Poco::File aFile(dest.parent());
aFile.createDirectories();
}
std::ofstream out(dest.toString().c_str(), std::ios::binary);
if (!out)
{
std::pair<const ZipLocalFileHeader, const std::string> tmp = std::make_pair(hdr, "Failed to open output stream " + dest.toString());
EError.notify(this, tmp);
return false;
}
ZipInputStream inp(zipStream, hdr, false);
Poco::StreamCopier::copyStream(inp, out);
out.close();
Poco::File aFile(file);
if (!aFile.exists() || !aFile.isFile())
{
std::pair<const ZipLocalFileHeader, const std::string> tmp = std::make_pair(hdr, "Failed to create output stream " + dest.toString());
EError.notify(this, tmp);
return false;
}
if (!inp.crcValid())
{
if (!_keepIncompleteFiles)
aFile.remove();
std::pair<const ZipLocalFileHeader, const std::string> tmp = std::make_pair(hdr, "CRC mismatch. Corrupt file: " + dest.toString());
EError.notify(this, tmp);
return false;
}
// cannot check against hdr.getUnCompressedSize if CRC and size are not set in hdr but in a ZipDataInfo
// crc is typically enough to detect errors
if (aFile.getSize() != hdr.getUncompressedSize() && !hdr.searchCRCAndSizesAfterData())
{
if (!_keepIncompleteFiles)
aFile.remove();
std::pair<const ZipLocalFileHeader, const std::string> tmp = std::make_pair(hdr, "Filesizes do not match. Corrupt file: " + dest.toString());
EError.notify(this, tmp);
return false;
}
std::pair<const ZipLocalFileHeader, const Poco::Path> tmp = std::make_pair(hdr, file);
EOk.notify(this, tmp);
}
catch (Poco::Exception& e)
{
std::pair<const ZipLocalFileHeader, const std::string> tmp = std::make_pair(hdr, "Exception: " + e.displayText());
EError.notify(this, tmp);
return false;
}
catch (...)
{
std::pair<const ZipLocalFileHeader, const std::string> tmp = std::make_pair(hdr, "Unknown Exception");
EError.notify(this, tmp);
return false;
}
return true;
}
void Decompress::onOk(const void*, std::pair<const ZipLocalFileHeader, const Poco::Path>& val)
{
_mapping.insert(std::make_pair(val.first.getFileName(), val.second));
}
} } // namespace Poco::Zip

63
Zip/src/Delete.cpp Normal file
View File

@ -0,0 +1,63 @@
//
// Delete.cpp
//
// $Id: //poco/1.3/Zip/src/Delete.cpp#1 $
//
// Library: Zip
// Package: Manipulation
// Module: Delete
//
// 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.
//
#include "Poco/Zip/Delete.h"
namespace Poco {
namespace Zip {
Delete::Delete(const ZipLocalFileHeader& hdr):
_hdr(hdr)
{
}
void Delete::execute(Compress& c, std::istream& input)
{
// due to absolute positioning in compress we don't need to do this
/*
input.seekg(_hdr.getEndPos(), std::ios_base::beg);
if (_hdr.searchCRCAndSizesAfterData())
{
ZipDataInfo info(in, false);
}
*/
}
} } // namespace Poco::Zip

59
Zip/src/Keep.cpp Normal file
View File

@ -0,0 +1,59 @@
//
// Keep.cpp
//
// $Id: //poco/1.3/Zip/src/Keep.cpp#1 $
//
// Library: Zip
// Package: Manipulation
// Module: Keep
//
// 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.
//
#include "Poco/Zip/Keep.h"
#include "Poco/Zip/Compress.h"
#include "Poco/Buffer.h"
#include "Poco/StreamCopier.h"
namespace Poco {
namespace Zip {
Keep::Keep(const ZipLocalFileHeader& hdr):
_hdr(hdr)
{
}
void Keep::execute(Compress& c, std::istream& input)
{
c.addFileRaw(input, _hdr, _hdr.getFileName());
}
} } // namespace Poco::Zip

54
Zip/src/ParseCallback.cpp Normal file
View File

@ -0,0 +1,54 @@
//
// ParseCallback.cpp
//
// $Id: //poco/1.3/Zip/src/ParseCallback.cpp#3 $
//
// Library: Zip
// Package: Zip
// Module: ParseCallback
//
// 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.
//
#include "Poco/Zip/ParseCallback.h"
namespace Poco {
namespace Zip {
ParseCallback::ParseCallback()
{
}
ParseCallback::~ParseCallback()
{
}
} } // namespace Poco::Zip

269
Zip/src/PartialStream.cpp Normal file
View File

@ -0,0 +1,269 @@
//
// PartialStream.cpp
//
// $Id: //poco/1.3/Zip/src/PartialStream.cpp#3 $
//
// Library: Zip
// Package: Zip
// Module: PartialStream
//
// 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.
//
#include "Poco/Zip/PartialStream.h"
#include "Poco/Exception.h"
#include <cstring>
namespace Poco {
namespace Zip {
PartialStreamBuf::PartialStreamBuf(std::istream& in, std::ios::pos_type start, std::ios::pos_type end, const std::string& pre, const std::string& post, bool initStream):
Poco::BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::in),
_initialized(!initStream),
_start(start),
_numBytes(end-start),
_bytesWritten(0),
_pIstr(&in),
_pOstr(0),
_prefix(pre),
_postfix(post),
_ignoreStart(0),
_buffer(0),
_bufferOffset(0)
{
}
PartialStreamBuf::PartialStreamBuf(std::ostream& out, std::size_t start, std::size_t end, bool initStream):
Poco::BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::out),
_initialized(!initStream),
_start(0),
_numBytes(0),
_bytesWritten(0),
_pIstr(0),
_pOstr(&out),
_ignoreStart(start),
_buffer(end),
_bufferOffset(0)
{
}
PartialStreamBuf::~PartialStreamBuf()
{
}
int PartialStreamBuf::readFromDevice(char* buffer, std::streamsize length)
{
if (_pIstr == 0 ||length == 0) return -1;
if (!_initialized)
{
_initialized = true;
_pIstr->clear();
_pIstr->seekg(_start, std::ios_base::beg);
if (_pIstr->fail())
throw Poco::IOException("Failed to reposition in stream");
}
if (!_prefix.empty())
{
std::streamsize tmp = (_prefix.size() > length)? length: static_cast<std::streamsize>(_prefix.size());
std::memcpy(buffer, _prefix.c_str(), tmp);
_prefix = _prefix.substr(tmp);
return tmp;
}
if (_numBytes == 0)
{
if (!_postfix.empty())
{
std::streamsize tmp = (_postfix.size() > length)? length: static_cast<std::streamsize>(_postfix.size());
std::memcpy(buffer, _postfix.c_str(), tmp);
_postfix = _postfix.substr(tmp);
return tmp;
}
else
return -1;
}
if (!_pIstr->good())
return -1;
if (_numBytes < length)
length = static_cast<std::streamsize>(_numBytes);
_pIstr->read(buffer, length);
std::streamsize bytesRead = _pIstr->gcount();
_numBytes -= bytesRead;
return bytesRead;
}
int PartialStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
{
if (_pOstr == 0 || length == 0) return -1;
if (!_initialized)
{
_initialized = true;
_pOstr->clear();
if (_pOstr->fail())
throw Poco::IOException("Failed to clear stream status");
}
if (_ignoreStart > 0)
{
if (_ignoreStart > length)
{
_ignoreStart -= length;
// fake return values
return length;
}
else
{
std::streamsize cnt = static_cast<std::streamsize>(length - _ignoreStart - _buffer.size());
if (cnt > 0)
{
_pOstr->write(buffer+_ignoreStart, cnt);
_bytesWritten += cnt;
}
// copy the rest into buffer
cnt += static_cast<std::streamsize>(_ignoreStart);
_ignoreStart = 0;
poco_assert (cnt < length);
_bufferOffset = length - cnt;
std::memcpy(_buffer.begin(), buffer + cnt, _bufferOffset);
return length;
}
}
if (_buffer.size() > 0)
{
// always treat each write as the potential last one
// thus first fill the buffer with the last n bytes of the msg
// how much of the already cached data do we need to write?
Poco::Int32 cache = _bufferOffset + length - _buffer.size();
if (cache > 0)
{
if (cache > _bufferOffset)
cache = _bufferOffset;
_pOstr->write(_buffer.begin(), cache);
_bytesWritten += cache;
_bufferOffset -= cache;
if (_bufferOffset > 0)
std::memmove(_buffer.begin(), _buffer.begin()+cache, _bufferOffset);
}
// now fill up _buffer with the last bytes from buffer
Poco::Int32 pos = static_cast<Poco::Int32>(length - static_cast<Poco::Int32>(_buffer.size()) + _bufferOffset);
if (pos <= 0)
{
// all of the message goes to _buffer
std::memcpy(_buffer.begin() + _bufferOffset, buffer, length);
}
else
{
poco_assert (_bufferOffset == 0);
std::memcpy(_buffer.begin(), buffer+pos, _buffer.size());
_bufferOffset = static_cast<Poco::UInt32>(_buffer.size());
// the rest is written
_pOstr->write(buffer, static_cast<std::streamsize>(length - _buffer.size()));
_bytesWritten += (length - _buffer.size());
}
}
else
{
_pOstr->write(buffer, length);
_bytesWritten += length;
}
if (_pOstr->good())
return length;
throw Poco::IOException("Failed to write to output stream");
}
void PartialStreamBuf::close()
{
// DONT write data from _buffer!
}
PartialIOS::PartialIOS(std::istream& istr, std::ios::pos_type start, std::ios::pos_type end, const std::string& pre, const std::string& post, bool initStream): _buf(istr, start, end, pre, post, initStream)
{
poco_ios_init(&_buf);
}
PartialIOS::PartialIOS(std::ostream& ostr, std::size_t start, std::size_t end, bool initStream): _buf(ostr, start, end, initStream)
{
poco_ios_init(&_buf);
}
PartialIOS::~PartialIOS()
{
}
PartialStreamBuf* PartialIOS::rdbuf()
{
return &_buf;
}
PartialInputStream::PartialInputStream(std::istream& istr, std::ios::pos_type start, std::ios::pos_type end, bool initStream, const std::string& pre, const std::string& post):
PartialIOS(istr, start, end, pre, post, initStream),
std::istream(&_buf)
{
}
PartialInputStream::~PartialInputStream()
{
}
PartialOutputStream::PartialOutputStream(std::ostream& ostr, std::size_t start, std::size_t end, bool initStream):
PartialIOS(ostr, start, end, initStream),
std::ostream(&_buf)
{
}
PartialOutputStream::~PartialOutputStream()
{
close();
}
} } // namespace Poco::Zip

58
Zip/src/Rename.cpp Normal file
View File

@ -0,0 +1,58 @@
//
// Rename.cpp
//
// $Id: //poco/1.3/Zip/src/Rename.cpp#1 $
//
// Library: Zip
// Package: Manipulation
// Module: Rename
//
// 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.
//
#include "Poco/Zip/Rename.h"
#include "Poco/Zip/Compress.h"
namespace Poco {
namespace Zip {
Rename::Rename(const ZipLocalFileHeader& hdr, const std::string& newZipEntryName):
_hdr(hdr),
_newZipEntryName(newZipEntryName)
{
}
void Rename::execute(Compress& c, std::istream& input)
{
c.addFileRaw(input, _hdr, _newZipEntryName);
}
} } // namespace Poco::Zip

60
Zip/src/Replace.cpp Normal file
View File

@ -0,0 +1,60 @@
//
// Replace.cpp
//
// $Id: //poco/1.3/Zip/src/Replace.cpp#1 $
//
// Library: Zip
// Package: Manipulation
// Module: Replace
//
// 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.
//
#include "Poco/Zip/Replace.h"
#include "Poco/Zip/Compress.h"
namespace Poco {
namespace Zip {
Replace::Replace(const ZipLocalFileHeader& hdr, const std::string& localPath):
_del(hdr),
_add(hdr.getFileName(), localPath, hdr.getCompressionMethod(), hdr.getCompressionLevel())
{
}
void Replace::execute(Compress& c, std::istream& input)
{
_del.execute(c, input);
_add.execute(c, input);
}
} } // namespace Poco::Zip

66
Zip/src/SkipCallback.cpp Normal file
View File

@ -0,0 +1,66 @@
//
// SkipCallback.cpp
//
// $Id: //poco/1.3/Zip/src/SkipCallback.cpp#4 $
//
// Library: Zip
// Package: Zip
// Module: SkipCallback
//
// 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.
//
#include "Poco/Zip/SkipCallback.h"
#include "Poco/Zip/ZipLocalFileHeader.h"
#include "Poco/Zip/ZipUtil.h"
namespace Poco {
namespace Zip {
SkipCallback::SkipCallback()
{
}
SkipCallback::~SkipCallback()
{
}
bool SkipCallback::handleZipEntry(std::istream& zipStream, const ZipLocalFileHeader& hdr)
{
if (!hdr.searchCRCAndSizesAfterData())
zipStream.seekg(hdr.getCompressedSize(), std::ios_base::cur);
else
ZipUtil::sync(zipStream);
return true;
}
} } // namespace Poco::Zip

122
Zip/src/ZipArchive.cpp Normal file
View File

@ -0,0 +1,122 @@
//
// ZipArchive.cpp
//
// $Id: //poco/1.3/Zip/src/ZipArchive.cpp#3 $
//
// Library: Zip
// Package: Zip
// Module: ZipArchive
//
// 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.
//
#include "Poco/Zip/ZipArchive.h"
#include "Poco/Zip/SkipCallback.h"
#include "Poco/Exception.h"
#include <cstring>
namespace Poco {
namespace Zip {
ZipArchive::ZipArchive(std::istream& in):
_entries(),
_infos(),
_disks()
{
poco_assert_dbg (in);
SkipCallback skip;
parse(in, skip);
}
ZipArchive::ZipArchive(const FileHeaders& entries, const FileInfos& infos, const DirectoryInfos& dirs):
_entries(entries),
_infos(infos),
_disks(dirs)
{
}
ZipArchive::ZipArchive(std::istream& in, ParseCallback& pc):
_entries(),
_infos(),
_disks()
{
poco_assert_dbg (in);
parse(in, pc);
}
ZipArchive::~ZipArchive()
{
}
void ZipArchive::parse(std::istream& in, ParseCallback& pc)
{
// read 4 bytes
while (in.good() && !in.eof())
{
char header[ZipCommon::HEADER_SIZE]={'\x00', '\x00', '\x00', '\x00'};
in.read(header, ZipCommon::HEADER_SIZE);
if (in.eof())
return;
if (std::memcmp(header, ZipLocalFileHeader::HEADER, ZipCommon::HEADER_SIZE) == 0)
{
ZipLocalFileHeader entry(in, true, pc);
poco_assert (_entries.insert(std::make_pair(entry.getFileName(), entry)).second);
}
else if (std::memcmp(header, ZipFileInfo::HEADER, ZipCommon::HEADER_SIZE) == 0)
{
ZipFileInfo info(in, true);
FileHeaders::iterator it = _entries.find(info.getFileName());
if (it != _entries.end())
{
it->second.setStartPos(info.getRelativeOffsetOfLocalHeader());
}
poco_assert (_infos.insert(std::make_pair(info.getFileName(), info)).second);
}
else if (std::memcmp(header, ZipArchiveInfo::HEADER, ZipCommon::HEADER_SIZE) == 0)
{
ZipArchiveInfo nfo(in, true);
poco_assert (_disks.insert(std::make_pair(nfo.getDiskNumber(), nfo)).second);
}
else
{
if (_disks.empty())
throw Poco::IllegalStateException("Illegal header in zip file");
else
throw Poco::IllegalStateException("Garbage after directory header");
}
}
}
} } // namespace Poco::Zip

106
Zip/src/ZipArchiveInfo.cpp Normal file
View File

@ -0,0 +1,106 @@
//
// ZipArchiveInfo.cpp
//
// $Id: //poco/1.3/Zip/src/ZipArchiveInfo.cpp#3 $
//
// Library: Zip
// Package: Zip
// Module: ZipArchiveInfo
//
// 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.
//
#include "Poco/Zip/ZipArchiveInfo.h"
#include "Poco/Buffer.h"
#include <istream>
#include <cstring>
namespace Poco {
namespace Zip {
const char ZipArchiveInfo::HEADER[ZipCommon::HEADER_SIZE] = {'\x50', '\x4b', '\x05', '\x06'};
ZipArchiveInfo::ZipArchiveInfo(std::istream& in, bool assumeHeaderRead):
_rawInfo(),
_startPos(in.tellg()),
_comment()
{
if (assumeHeaderRead)
_startPos -= ZipCommon::HEADER_SIZE;
parse(in, assumeHeaderRead);
}
ZipArchiveInfo::ZipArchiveInfo():
_rawInfo(),
_startPos(0),
_comment()
{
std::memset(_rawInfo, 0, FULLHEADER_SIZE);
std::memcpy(_rawInfo, HEADER, ZipCommon::HEADER_SIZE);
}
ZipArchiveInfo::~ZipArchiveInfo()
{
}
void ZipArchiveInfo::parse(std::istream& inp, bool assumeHeaderRead)
{
if (!assumeHeaderRead)
{
inp.read(_rawInfo, ZipCommon::HEADER_SIZE);
}
else
{
std::memcpy(_rawInfo, HEADER, ZipCommon::HEADER_SIZE);
}
poco_assert (std::memcmp(_rawInfo, HEADER, ZipCommon::HEADER_SIZE) == 0);
// read the rest of the header
inp.read(_rawInfo + ZipCommon::HEADER_SIZE, FULLHEADER_SIZE - ZipCommon::HEADER_SIZE);
Poco::UInt16 len = getZipCommentSize();
if (len > 0)
{
Poco::Buffer<char> buf(len);
inp.read(buf.begin(), len);
_comment = std::string(buf.begin(), len);
}
}
std::string ZipArchiveInfo::createHeader() const
{
std::string result(_rawInfo, FULLHEADER_SIZE);
result.append(_comment);
return result;
}
} } // namespace Poco::Zip

47
Zip/src/ZipCommon.cpp Normal file
View File

@ -0,0 +1,47 @@
//
// ZipCommon.cpp
//
// $Id: //poco/1.3/Zip/src/ZipCommon.cpp#3 $
//
// Library: Zip
// Package: Zip
// Module: ZipCommon
//
// 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.
//
#include "Poco/Zip/ZipCommon.h"
namespace Poco {
namespace Zip {
const std::string ZipCommon::ILLEGAL_PATH("..");
} } // namespace Poco::Zip

79
Zip/src/ZipDataInfo.cpp Normal file
View File

@ -0,0 +1,79 @@
//
// ZipDataInfo.cpp
//
// $Id: //poco/1.3/Zip/src/ZipDataInfo.cpp#3 $
//
// Library: Zip
// Package: Zip
// Module: ZipDataInfo
//
// 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.
//
#include "Poco/Zip/ZipDataInfo.h"
#include <istream>
#include <cstring>
namespace Poco {
namespace Zip {
const char ZipDataInfo::HEADER[ZipCommon::HEADER_SIZE] = {'\x50', '\x4b', '\x07', '\x08'};
ZipDataInfo::ZipDataInfo():
_rawInfo(),
_valid(true)
{
std::memcpy(_rawInfo, HEADER, ZipCommon::HEADER_SIZE);
std::memset(_rawInfo+ZipCommon::HEADER_SIZE, 0, FULLHEADER_SIZE - ZipCommon::HEADER_SIZE);
_valid = true;
}
ZipDataInfo::ZipDataInfo(std::istream& in, bool assumeHeaderRead):
_rawInfo(),
_valid(false)
{
if (assumeHeaderRead)
std::memcpy(_rawInfo, HEADER, ZipCommon::HEADER_SIZE);
else
in.read(_rawInfo, ZipCommon::HEADER_SIZE);
poco_assert (std::memcmp(_rawInfo, HEADER, ZipCommon::HEADER_SIZE) == 0);
// now copy the rest of the header
in.read(_rawInfo+ZipCommon::HEADER_SIZE, FULLHEADER_SIZE - ZipCommon::HEADER_SIZE);
_valid = (!in.eof() && in.good());
}
ZipDataInfo::~ZipDataInfo()
{
}
} } // namespace Poco::Zip

49
Zip/src/ZipException.cpp Normal file
View File

@ -0,0 +1,49 @@
//
// ZipException.cpp
//
// $Id: //poco/1.3/Zip/src/ZipException.cpp#4 $
//
// Library: Zip
// Package: Zip
// Module: ZipException
//
// 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.
//
#include "Poco/Zip/ZipException.h"
#include <typeinfo>
namespace Poco {
namespace Zip {
POCO_IMPLEMENT_EXCEPTION(ZipException, Poco::RuntimeException, "ZIP Exception")
POCO_IMPLEMENT_EXCEPTION(ZipManipulationException, ZipException, "ZIP Manipulation Exception")
} } // namespace Poco::Zip

143
Zip/src/ZipFileInfo.cpp Normal file
View File

@ -0,0 +1,143 @@
//
// ZipFileInfo.cpp
//
// $Id: //poco/1.3/Zip/src/ZipFileInfo.cpp#4 $
//
// Library: Zip
// Package: Zip
// 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.
//
#include "Poco/Zip/ZipFileInfo.h"
#include "Poco/Zip/ZipLocalFileHeader.h"
#include "Poco/Buffer.h"
#include <istream>
#include <cstring>
namespace Poco {
namespace Zip {
const char ZipFileInfo::HEADER[ZipCommon::HEADER_SIZE] = {'\x50', '\x4b', '\x01', '\x02'};
ZipFileInfo::ZipFileInfo(const ZipLocalFileHeader& header):
_rawInfo(),
_crc32(0),
_compressedSize(0),
_uncompressedSize(0),
_fileName(),
_lastModifiedAt(),
_extraField()
{
std::memset(_rawInfo, 0, FULLHEADER_SIZE);
std::memcpy(_rawInfo, HEADER, ZipCommon::HEADER_SIZE);
setCompressedSize(header.getCompressedSize());
setUncompressedSize(header.getUncompressedSize());
setCRC(header.getCRC());
setCompressionMethod(header.getCompressionMethod());
setCompressionLevel(header.getCompressionLevel());
setRequiredVersion(header.getMajorVersionNumber(), header.getMinorVersionNumber());
setHostSystem(header.getHostSystem());
setLastModifiedAt(header.lastModifiedAt());
setEncryption(false);
setFileName(header.getFileName());
}
ZipFileInfo::ZipFileInfo(std::istream& in, bool assumeHeaderRead):
_rawInfo(),
_crc32(0),
_compressedSize(0),
_uncompressedSize(0),
_fileName(),
_lastModifiedAt(),
_extraField()
{
// sanity check
poco_assert_dbg (RELATIVEOFFSETLOCALHEADER_POS + RELATIVEOFFSETLOCALHEADER_SIZE == FULLHEADER_SIZE);
parse(in, assumeHeaderRead);
}
ZipFileInfo::~ZipFileInfo()
{
}
void ZipFileInfo::parse(std::istream& inp, bool assumeHeaderRead)
{
if (!assumeHeaderRead)
{
inp.read(_rawInfo, ZipCommon::HEADER_SIZE);
}
else
{
std::memcpy(_rawInfo, HEADER, ZipCommon::HEADER_SIZE);
}
poco_assert (std::memcmp(_rawInfo, HEADER, ZipCommon::HEADER_SIZE) == 0);
// read the rest of the header
inp.read(_rawInfo + ZipCommon::HEADER_SIZE, FULLHEADER_SIZE - ZipCommon::HEADER_SIZE);
_crc32 = getCRCFromHeader();
_compressedSize = getCompressedSizeFromHeader();
_uncompressedSize = getUncompressedSizeFromHeader();
parseDateTime();
Poco::UInt16 len = getFileNameLength();
Poco::Buffer<char> buf(len);
inp.read(buf.begin(), len);
_fileName = std::string(buf.begin(), len);
if (hasExtraField())
{
len = getExtraFieldLength();
Poco::Buffer<char> xtra(len);
inp.read(xtra.begin(), len);
_extraField = std::string(xtra.begin(), len);
}
len = getFileCommentLength();
if (len > 0)
{
Poco::Buffer<char> buf2(len);
inp.read(buf2.begin(), len);
_fileComment = std::string(buf2.begin(), len);
}
}
std::string ZipFileInfo::createHeader() const
{
std::string result(_rawInfo, FULLHEADER_SIZE);
result.append(_fileName);
result.append(_extraField);
result.append(_fileComment);
return result;
}
} } // namespace Poco::Zip

View File

@ -0,0 +1,238 @@
//
// ZipLocalFileHeader.cpp
//
// $Id: //poco/1.3/Zip/src/ZipLocalFileHeader.cpp#4 $
//
// Library: Zip
// Package: Zip
// Module: ZipLocalFileHeader
//
// 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.
//
#include "Poco/Zip/ZipLocalFileHeader.h"
#include "Poco/Zip/ZipDataInfo.h"
#include "Poco/Zip/ParseCallback.h"
#include "Poco/Buffer.h"
#include "Poco/Exception.h"
#include "Poco/File.h"
#include <cstring>
namespace Poco {
namespace Zip {
const char ZipLocalFileHeader::HEADER[ZipCommon::HEADER_SIZE] = {'\x50', '\x4b', '\x03', '\x04'};
ZipLocalFileHeader::ZipLocalFileHeader(const Poco::Path& fileName,
const Poco::DateTime& lastModifiedAt,
ZipCommon::CompressionMethod cm,
ZipCommon::CompressionLevel cl):
_rawHeader(),
_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;
#if (POCO_OS == POCO_OS_CYGWIN)
hs = ZipCommon::HS_UNIX;
#endif
#if (POCO_OS == POCO_OS_VMS)
hs = ZipCommon::HS_VMS;
#endif
#if defined(POCO_OS_FAMILY_UNIX)
hs = ZipCommon::HS_UNIX;
#endif
setHostSystem(hs);
setEncryption(false);
setExtraFieldSize(0);
setLastModifiedAt(lastModifiedAt);
init(fileName, cm, cl);
}
ZipLocalFileHeader::ZipLocalFileHeader(std::istream& inp, bool assumeHeaderRead, ParseCallback& callback):
_rawHeader(),
_startPos(inp.tellg()),
_endPos(-1),
_fileName(),
_lastModifiedAt(),
_extraField(),
_crc32(0),
_compressedSize(0),
_uncompressedSize(0)
{
poco_assert_dbg( (EXTRAFIELD_POS+EXTRAFIELD_LENGTH) == FULLHEADER_SIZE);
if (assumeHeaderRead)
_startPos -= ZipCommon::HEADER_SIZE;
parse(inp, assumeHeaderRead);
bool ok = callback.handleZipEntry(inp, *this);
if (ok)
{
if (searchCRCAndSizesAfterData())
{
ZipDataInfo nfo(inp, false);
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!
}
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() <= 2);
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 (hasExtraField())
{
len = getExtraFieldLength();
Poco::Buffer<char> xtra(len);
inp.read(xtra.begin(), len);
_extraField = std::string(xtra.begin(), len);
}
if (!searchCRCAndSizesAfterData())
{
_crc32 = getCRCFromHeader();
_compressedSize = getCompressedSizeFromHeader();
_uncompressedSize = getUncompressedSizeFromHeader();
}
}
bool ZipLocalFileHeader::searchCRCAndSizesAfterData() const
{
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);
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)
{
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);
}
std::string ZipLocalFileHeader::createHeader() const
{
std::string result(_rawHeader, FULLHEADER_SIZE);
result.append(_fileName);
result.append(_extraField);
return result;
}
} } // namespace Poco::Zip

194
Zip/src/ZipManipulator.cpp Normal file
View File

@ -0,0 +1,194 @@
//
// ZipManipulator.cpp
//
// $Id: //poco/1.3/Zip/src/ZipManipulator.cpp#2 $
//
// Library: Zip
// Package: Manipulation
// Module: ZipManipulator
//
// 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.
//
#include "Poco/Zip/ZipManipulator.h"
#include "Poco/Zip/ZipException.h"
#include "Poco/Zip/ZipUtil.h"
#include "Poco/Zip/Add.h"
#include "Poco/Zip/Delete.h"
#include "Poco/Zip/Keep.h"
#include "Poco/Zip/Rename.h"
#include "Poco/Zip/Replace.h"
#include "Poco/Zip/Compress.h"
#include "Poco/Delegate.h"
#include "Poco/File.h"
#include "Poco/FileStream.h"
#include <fstream>
namespace Poco {
namespace Zip {
ZipManipulator::ZipManipulator(const std::string& zipFile, bool backupOriginalFile):
_zipFile(zipFile),
_backupOriginalFile(backupOriginalFile),
_changes(),
_in(0)
{
std::ifstream in(zipFile.c_str());
_in = new ZipArchive(in);
}
ZipManipulator::~ZipManipulator()
{
}
void ZipManipulator::deleteFile(const std::string& zipPath)
{
const ZipLocalFileHeader& entry = getForChange(zipPath);
addOperation(zipPath, new Delete(entry));
}
void ZipManipulator::replaceFile(const std::string& zipPath, const std::string& localPath)
{
const ZipLocalFileHeader& entry = getForChange(zipPath);
addOperation(zipPath, new Replace(entry, localPath));
}
void ZipManipulator::renameFile(const std::string& zipPath, const std::string& newZipPath)
{
const ZipLocalFileHeader& entry = getForChange(zipPath);
// checked later in Compress too but the earlier one gets the error the better
std::string fn = ZipUtil::validZipEntryFileName(newZipPath);
addOperation(zipPath, new Rename(entry, fn));
}
void ZipManipulator::addFile(const std::string& zipPath, const std::string& localPath, ZipCommon::CompressionMethod cm, ZipCommon::CompressionLevel cl)
{
addOperation(zipPath, new Add(zipPath, localPath, cm, cl));
}
ZipArchive ZipManipulator::commit()
{
// write to a tmp file
std::string outFile(_zipFile + ".tmp");
ZipArchive retVal(compress(outFile));
//renaming
{
Poco::File aFile(_zipFile);
if (_backupOriginalFile)
{
Poco::File tmp(_zipFile+".bak");
if (tmp.exists())
tmp.remove();
aFile.renameTo(_zipFile+".bak");
}
else
aFile.remove();
}
{
Poco::File resFile(outFile);
Poco::File zipFile(_zipFile);
if (zipFile.exists())
zipFile.remove();
resFile.renameTo(_zipFile);
}
return retVal;
}
const ZipLocalFileHeader& ZipManipulator::getForChange(const std::string& zipPath) const
{
ZipArchive::FileHeaders::const_iterator it = _in->findHeader(zipPath);
if (it == _in->headerEnd())
throw ZipManipulationException("entry not found: " + zipPath);
if (_changes.find(zipPath) != _changes.end())
throw ZipManipulationException("A change request exists already for entry " + zipPath);
return it->second;
}
void ZipManipulator::addOperation(const std::string& zipPath, ZipOperation::Ptr ptrOp)
{
std::pair<Changes::iterator, bool> result = _changes.insert(std::make_pair(zipPath, ptrOp));
if (!result.second)
throw ZipManipulationException("A change request exists already for entry " + zipPath);
}
void ZipManipulator::onEDone(const void*, const ZipLocalFileHeader& hdr)
{
EDone(this, hdr);
}
ZipArchive ZipManipulator::compress(const std::string& outFile)
{
// write to a tmp file
Poco::FileInputStream in(_zipFile);
Poco::FileOutputStream out(outFile);
Compress c(out, true);
c.EDone += Poco::Delegate<ZipManipulator, const ZipLocalFileHeader>(this, &ZipManipulator::onEDone);
ZipArchive::FileHeaders::const_iterator it = _in->headerBegin();
for (; it != _in->headerEnd(); ++it)
{
Changes::iterator itC = _changes.find(it->first);
if (itC != _changes.end())
{
itC->second->execute(c, in);
_changes.erase(itC);
}
else
{
Keep k(it->second);
k.execute(c, in);
}
}
//Remaining files are add operations!
Changes::iterator itC = _changes.begin();
for (; itC != _changes.end(); ++itC)
{
itC->second->execute(c, in);
}
_changes.clear();
c.EDone -= Poco::Delegate<ZipManipulator, const ZipLocalFileHeader>(this, &ZipManipulator::onEDone);
in.close();
return c.close();
}
} } // namespace Poco::Zip

54
Zip/src/ZipOperation.cpp Normal file
View File

@ -0,0 +1,54 @@
//
// ZipOperation.cpp
//
// $Id: //poco/1.3/Zip/src/ZipOperation.cpp#1 $
//
// Library: Zip
// Package: Manipulation
// Module: ZipOperation
//
// 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.
//
#include "Poco/Zip/ZipOperation.h"
namespace Poco {
namespace Zip {
ZipOperation::ZipOperation()
{
}
ZipOperation::~ZipOperation()
{
}
} } // namespace Poco::Zip

319
Zip/src/ZipStream.cpp Normal file
View File

@ -0,0 +1,319 @@
//
// ZipStream.cpp
//
// $Id: //poco/1.3/Zip/src/ZipStream.cpp#4 $
//
// Library: Zip
// Package: Zip
// Module: ZipStream
//
// 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.
//
#include "Poco/Zip/ZipStream.h"
#include "Poco/zlib.h"
#include "Poco/Zip/ZipArchive.h"
#include "Poco/Zip/AutoDetectStream.h"
#include "Poco/Zip/PartialStream.h"
#include "Poco/Zip/ZipDataInfo.h"
#include "Poco/Zip/ZipException.h"
#include "Poco/Exception.h"
#include "Poco/InflatingStream.h"
#include "Poco/DeflatingStream.h"
namespace Poco {
namespace Zip {
ZipStreamBuf::ZipStreamBuf(std::istream& istr, const ZipLocalFileHeader& fileEntry, bool reposition):
Poco::BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::in),
_pIstr(&istr),
_pOstr(0),
_ptrBuf(),
_ptrOBuf(),
_ptrHelper(),
_ptrOHelper(),
_crc32(Poco::Checksum::TYPE_CRC32),
_expectedCrc32(0),
_checkCRC(true),
_bytesWritten(0),
_pHeader(0)
{
if (fileEntry.isDirectory())
return;
_expectedCrc32 = fileEntry.getCRC();
std::streamoff start = fileEntry.getDataStartPos();
std::streamoff end = fileEntry.getDataEndPos();
_checkCRC = !fileEntry.searchCRCAndSizesAfterData();
if (fileEntry.getCompressionMethod() == ZipCommon::CM_DEFLATE)
{
// Fake init bytes at beginning of stream
std::string init = ZipUtil::fakeZLibInitString(fileEntry.getCompressionLevel());
// Fake adler at end of stream: just some dummy value, not checked anway
std::string crc(4, ' ');
if (fileEntry.searchCRCAndSizesAfterData())
{
_ptrHelper = new AutoDetectInputStream(istr, init, crc, reposition, start);
}
else
_ptrHelper = new PartialInputStream(istr, start, end, reposition, init, crc);
_ptrBuf = new Poco::InflatingInputStream(*_ptrHelper, Poco::InflatingStreamBuf::STREAM_ZIP);
}
else if (fileEntry.getCompressionMethod() == ZipCommon::CM_STORE)
{
if (fileEntry.searchCRCAndSizesAfterData())
{
_ptrBuf = new AutoDetectInputStream(istr, "", "", reposition, start);
}
else
_ptrBuf = new PartialInputStream(istr, start, end, reposition);
}
else
{
throw Poco::NotImplementedException("Unsupported compression method");
}
}
ZipStreamBuf::ZipStreamBuf(std::ostream& ostr, ZipLocalFileHeader& fileEntry, bool reposition):
Poco::BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::out),
_pIstr(0),
_pOstr(&ostr),
_ptrBuf(),
_ptrOBuf(),
_ptrHelper(),
_ptrOHelper(),
_crc32(Poco::Checksum::TYPE_CRC32),
_expectedCrc32(0),
_checkCRC(false),
_bytesWritten(0),
_pHeader(&fileEntry)
{
if (fileEntry.isEncrypted())
throw Poco::NotImplementedException("Encryption not supported");
if (fileEntry.isDirectory())
{
// only header, no payload, zero crc
fileEntry.setSearchCRCAndSizesAfterData(false);
fileEntry.setCompressedSize(0);
fileEntry.setUncompressedSize(0);
fileEntry.setCRC(0);
std::string header = fileEntry.createHeader();
ostr.write(header.c_str(), static_cast<std::streamsize>(header.size()));
}
else
{
fileEntry.setSearchCRCAndSizesAfterData(!reposition);
if (fileEntry.getCompressionMethod() == ZipCommon::CM_DEFLATE)
{
int level = Z_DEFAULT_COMPRESSION;
if (fileEntry.getCompressionLevel() == ZipCommon::CL_FAST || fileEntry.getCompressionLevel() == ZipCommon::CL_SUPERFAST)
level = Z_BEST_SPEED;
else if (fileEntry.getCompressionLevel() == ZipCommon::CL_MAXIMUM)
level = Z_BEST_COMPRESSION;
// ignore the zlib init string which is of size 2 and also ignore the 4 byte adler32 value at the end of the stream!
_ptrOHelper = new PartialOutputStream(*_pOstr, 2, 4, false);
_ptrOBuf = new Poco::DeflatingOutputStream(*_ptrOHelper, DeflatingStreamBuf::STREAM_ZLIB, level);
}
else if (fileEntry.getCompressionMethod() == ZipCommon::CM_STORE)
{
_ptrOHelper = new PartialOutputStream(*_pOstr, 0, 0, false);
_ptrOBuf = _ptrOHelper;
}
else
{
throw Poco::NotImplementedException("Unsupported compression method");
}
// now write the header to the ostr!
std::string header = fileEntry.createHeader();
ostr.write(header.c_str(), static_cast<std::streamsize>(header.size()));
}
}
ZipStreamBuf::~ZipStreamBuf()
{
}
int ZipStreamBuf::readFromDevice(char* buffer, std::streamsize length)
{
if (!_ptrBuf) return 0; // directory entry
_ptrBuf->read(buffer, length);
int cnt = _ptrBuf->gcount();
if (cnt > 0)
{
_crc32.update(buffer, cnt);
}
else
{
if (_crc32.checksum() != _expectedCrc32)
{
if (_checkCRC)
throw ZipException("CRC failure");
else
{
// the CRC value is written directly after the data block
// parse it directly from the input stream
ZipDataInfo nfo(*_pIstr, false);
// now push back the header to the stream, so that the ZipLocalFileHeader can read it
Poco::Int32 size = static_cast<Poco::Int32>(nfo.getFullHeaderSize());
_expectedCrc32 = nfo.getCRC32();
const char* rawHeader = nfo.getRawHeader();
for (Poco::Int32 i = size-1; i >= 0; --i)
_pIstr->putback(rawHeader[i]);
if (!crcValid())
throw ZipException("CRC failure");
}
}
}
return cnt;
}
int ZipStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
{
if (!_ptrOBuf) return 0; // directory entry
if (length == 0)
return 0;
_bytesWritten += length;
_ptrOBuf->write(buffer, length);
_crc32.update(buffer, length);
return length;
}
void ZipStreamBuf::close()
{
if (_ptrOBuf && _pHeader)
{
_ptrOBuf->flush();
DeflatingOutputStream* pDO = dynamic_cast<DeflatingOutputStream*>(_ptrOBuf.get());
if (pDO)
pDO->close();
if (_ptrOHelper)
{
_ptrOHelper->flush();
_ptrOHelper->close();
}
_ptrOBuf = 0;
poco_assert (*_pOstr);
// write an extra datablock if required
// or fix the crc entries
if (_pHeader->searchCRCAndSizesAfterData())
{
ZipDataInfo info;
info.setCRC32(_crc32.checksum());
info.setUncompressedSize(_bytesWritten);
info.setCompressedSize(static_cast<Poco::UInt32>(_ptrOHelper->bytesWritten()));
_pOstr->write(info.getRawHeader(), static_cast<std::streamsize>(info.getFullHeaderSize()));
}
else
{
poco_check_ptr (_pHeader);
_pHeader->setCRC(_crc32.checksum());
_pHeader->setUncompressedSize(_bytesWritten);
_pHeader->setCompressedSize(static_cast<Poco::UInt32>(_ptrOHelper->bytesWritten()));
_pOstr->seekp(_pHeader->getStartPos(), std::ios_base::beg);
poco_assert (*_pOstr);
std::string header = _pHeader->createHeader();
_pOstr->write(header.c_str(), static_cast<std::streamsize>(header.size()));
_pOstr->seekp(0, std::ios_base::end);
poco_assert (*_pOstr);
}
_pHeader = 0;
}
}
bool ZipStreamBuf::crcValid() const
{
if (!_ptrBuf) return true; // directory entry
return _crc32.checksum() == _expectedCrc32;
}
ZipIOS::ZipIOS(std::istream& istr, const ZipLocalFileHeader& fileEntry, bool reposition): _buf(istr, fileEntry, reposition)
{
poco_ios_init(&_buf);
}
ZipIOS::ZipIOS(std::ostream& ostr, ZipLocalFileHeader& fileEntry, bool reposition): _buf(ostr, fileEntry, reposition)
{
poco_ios_init(&_buf);
}
ZipIOS::~ZipIOS()
{
}
ZipStreamBuf* ZipIOS::rdbuf()
{
return &_buf;
}
ZipInputStream::ZipInputStream(std::istream& istr, const ZipLocalFileHeader& fileEntry, bool reposition): ZipIOS(istr, fileEntry, reposition), std::istream(&_buf)
{
}
ZipInputStream::~ZipInputStream()
{
}
bool ZipInputStream::crcValid() const
{
return _buf.crcValid();
}
ZipOutputStream::ZipOutputStream(std::ostream& ostr, ZipLocalFileHeader& fileEntry, bool seekableOutput): ZipIOS(ostr, fileEntry, seekableOutput), std::ostream(&_buf)
{
}
ZipOutputStream::~ZipOutputStream()
{
}
void ZipOutputStream::close()
{
flush();
_buf.close();
}
} } // namespace Poco::Zip

212
Zip/src/ZipUtil.cpp Normal file
View File

@ -0,0 +1,212 @@
//
// ZipUtil.cpp
//
// $Id: //poco/1.3/Zip/src/ZipUtil.cpp#4 $
//
// Library: Zip
// Package: Zip
// Module: ZipUtil
//
// 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.
//
#include "Poco/Zip/ZipUtil.h"
#include "Poco/Zip/ZipException.h"
#include "Poco/Zip/ZipLocalFileHeader.h"
#include "Poco/Zip/ZipFileInfo.h"
#include "Poco/Zip/ZipDataInfo.h"
#include "Poco/Zip/ZipArchiveInfo.h"
#include <cstring>
namespace Poco {
namespace Zip {
Poco::DateTime ZipUtil::parseDateTime(const char* pVal, const Poco::UInt32 timePos, const Poco::UInt32 datePos)
{
Poco::UInt16 time = ZipUtil::get16BitValue(pVal, timePos);
Poco::UInt16 date = ZipUtil::get16BitValue(pVal, datePos);
//TIME: second 0-4, minute 5-10, hour 11-15, second resolution is 2!
int sec = 2*(time & 0x001fu); // 0000 0000 0001 1111
int min = ((time & 0x07e0u) >> 5); // 0000 0111 1110 0000
int hour= ((time & 0xf800u) >> 11); // 1111 1000 0000 0000
//DATE: day 0-4, month 5-8, year (starting with 1980): 9-16
int day = (date & 0x001fu); // 0000 0000 0001 1111
int mon = ((date & 0x01e0u) >> 5); // 0000 0001 1110 0000
int year= 1980+((date & 0xfe00u) >> 9); // 1111 1110 0000 0000
return Poco::DateTime(year, mon, day, hour, min, sec);
}
void ZipUtil::setDateTime(const Poco::DateTime& dt, char* pVal, const Poco::UInt32 timePos, const Poco::UInt32 datePos)
{
//TIME: second 0-4, minute 5-10, hour 11-15
Poco::UInt16 time = static_cast<Poco::UInt16>((dt.second()/2) + (dt.minute()<<5) + (dt.hour()<<11));
//DATE: day 0-4, month 5-8, year (starting with 1980): 9-16
int year = dt.year() - 1980;
if (year<0)
year = 0;
Poco::UInt16 date = static_cast<Poco::UInt16>(dt.day() + (dt.month()<<5) + (year<<9));
ZipUtil::set16BitValue(time, pVal, timePos);
ZipUtil::set16BitValue(date, pVal, datePos);
}
std::string ZipUtil::fakeZLibInitString(ZipCommon::CompressionLevel cl)
{
std::string init(2, ' ');
// compression info:
// deflate is used, bit 0-3: 0x08
// dictionary size is always 32k: calc ld2(32k)-8 = ld2(2^15) - 8 = 15 - 8 = 7 --> bit 4-7: 0x70
init[0] = '\x78';
// now fake flags
// bits 0-4 check bits: set them so that init[0]*256+init[1] % 31 == 0
// bit 5: preset dictionary? always no for us, set to 0
// bits 6-7: compression level: 00 very fast, 01 fast, 10 normal, 11 best
if (cl == ZipCommon::CL_SUPERFAST)
init[1] = '\x00';
else if (cl == ZipCommon::CL_FAST)
init[1] = '\x40';
else if (cl == ZipCommon::CL_NORMAL)
init[1] = '\x80';
else
init[1] = '\xc0';
// now set the last 5 bits
Poco::UInt16 tmpVal = ((Poco::UInt16)init[0])*256+((unsigned char)init[1]);
char checkBits = (31 - (char)(tmpVal%31));
init[1] |= checkBits; // set the lower 5 bits
tmpVal = ((Poco::UInt16)init[0])*256+((unsigned char)init[1]);
poco_assert_dbg ((tmpVal % 31) == 0);
return init;
}
void ZipUtil::sync(std::istream& in)
{
enum
{
PREFIX = 2,
BUFFER_SIZE = 1024
};
char temp[BUFFER_SIZE];
in.read(temp, PREFIX);
std::size_t tempPos = PREFIX;
while (in.good() && !in.eof())
{
// all zip headers start withe same 2byte prefix
if(std::memcmp(ZipLocalFileHeader::HEADER, &temp[tempPos - PREFIX], PREFIX) == 0)
{
// we have a possible header!
// read the next 2 bytes
in.read(temp+tempPos, PREFIX);
tempPos += PREFIX;
if (std::memcmp(ZipLocalFileHeader::HEADER+PREFIX, &temp[tempPos - PREFIX], PREFIX) == 0 ||
std::memcmp(ZipArchiveInfo::HEADER+PREFIX, &temp[tempPos - PREFIX], PREFIX) == 0 ||
std::memcmp(ZipFileInfo::HEADER+PREFIX, &temp[tempPos - PREFIX], PREFIX) == 0 ||
std::memcmp(ZipDataInfo::HEADER+PREFIX, &temp[tempPos - PREFIX], PREFIX) == 0)
{
if (std::memcmp(ZipLocalFileHeader::HEADER+PREFIX, &temp[tempPos - PREFIX], PREFIX) == 0)
{
in.putback(ZipLocalFileHeader::HEADER[3]);
in.putback(ZipLocalFileHeader::HEADER[2]);
in.putback(ZipLocalFileHeader::HEADER[1]);
in.putback(ZipLocalFileHeader::HEADER[0]);
}
else if (std::memcmp(ZipArchiveInfo::HEADER+PREFIX, &temp[tempPos - PREFIX], PREFIX) == 0)
{
in.putback(ZipArchiveInfo::HEADER[3]);
in.putback(ZipArchiveInfo::HEADER[2]);
in.putback(ZipArchiveInfo::HEADER[1]);
in.putback(ZipArchiveInfo::HEADER[0]);
}
else if (std::memcmp(ZipFileInfo::HEADER+PREFIX, &temp[tempPos - PREFIX], PREFIX) == 0)
{
in.putback(ZipFileInfo::HEADER[3]);
in.putback(ZipFileInfo::HEADER[2]);
in.putback(ZipFileInfo::HEADER[1]);
in.putback(ZipFileInfo::HEADER[0]);
}
else
{
in.putback(ZipDataInfo::HEADER[3]);
in.putback(ZipDataInfo::HEADER[2]);
in.putback(ZipDataInfo::HEADER[1]);
in.putback(ZipDataInfo::HEADER[0]);
}
return;
}
else
{
// we have read 2 bytes, should only be one: putback the last char
in.putback(temp[tempPos - 1]);
--tempPos;
}
}
else
{
// read one byte
in.read(temp + tempPos, 1);
++tempPos;
}
if (tempPos > (BUFFER_SIZE - ZipCommon::HEADER_SIZE))
{
std::memcpy(temp, &temp[tempPos - ZipCommon::HEADER_SIZE], ZipCommon::HEADER_SIZE);
tempPos = ZipCommon::HEADER_SIZE;
}
}
}
void ZipUtil::verifyZipEntryFileName(const std::string& fn)
{
if (fn.find("\\") != std::string::npos)
throw ZipException("Illegal entry name " + fn + " containing \\");
if (fn == "/")
throw ZipException("Illegal entry name /");
if (fn.empty())
throw ZipException("Illegal empty entry name");
if (fn.find(ZipCommon::ILLEGAL_PATH) != std::string::npos)
throw ZipException("Illegal entry name " + fn + " containing " + ZipCommon::ILLEGAL_PATH);
}
std::string ZipUtil::validZipEntryFileName(const Poco::Path& entry)
{
std::string fn = entry.toString(Poco::Path::PATH_UNIX);
verifyZipEntryFileName(fn);
return fn;
}
} } // namespace Poco::Zip

18
Zip/testsuite/Makefile Normal file
View File

@ -0,0 +1,18 @@
#
# Makefile
#
# $Id: //poco/1.3/Zip/testsuite/Makefile#1 $
#
# Makefile for Poco Zip testsuite
#
include $(POCO_BASE)/build/rules/global
objects = ZipTestSuite Driver \
ZipTest CompressTest PartialStreamTest
target = testrunner
target_version = 1
target_libs = PocoZip PocoNet PocoFoundation CppUnit
include $(POCO_BASE)/build/rules/exec

View File

@ -0,0 +1,9 @@
#
# TestSuite.vmsbuild
#
# $Id: //poco/1.3/Zip/testsuite/TestSuite.vmsbuild#1 $
#
EXE=TestRunner
ZipTestSuite
Driver
<SourceFilesHere>

View File

@ -0,0 +1,197 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="TestSuite"
ProjectGUID="{9665fc3c-db71-4c6c-aaee-aafd73cb31e7}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\include;..\..\Foundation\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;..\..\Net\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
BufferSecurityCheck="TRUE"
TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="TRUE"
RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="CppUnitd.lib WinTestRunnerd.lib PocoFoundationd.lib PocoZipd.lib PocoNetd.lib"
OutputFile="bin/TestSuited.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\lib"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="bin/TestSuited.pdb"
SubSystem="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="release_shared|Win32"
OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="4"
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="TRUE"
FavorSizeOrSpeed="1"
OmitFramePointers="TRUE"
OptimizeForWindowsApplication="TRUE"
AdditionalIncludeDirectories="..\include;..\..\Foundation\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;..\..\Net\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
StringPooling="TRUE"
RuntimeLibrary="2"
BufferSecurityCheck="FALSE"
TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="TRUE"
RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="CppUnit.lib WinTestRunner.lib PocoFoundation.lib PocoZip.lib PocoNet.lib"
OutputFile="bin/TestSuite.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\lib"
GenerateDebugInformation="FALSE"
ProgramDatabaseFile=""
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Zip"
Filter="">
<Filter
Name="Header Files"
Filter="">
<File
RelativePath=".\src\CompressTest.h">
</File>
<File
RelativePath=".\src\PartialStreamTest.h">
</File>
<File
RelativePath=".\src\ZipTest.h">
</File>
</Filter>
<Filter
Name="Source Files"
Filter="">
<File
RelativePath=".\src\CompressTest.cpp">
</File>
<File
RelativePath=".\src\PartialStreamTest.cpp">
</File>
<File
RelativePath=".\src\ZipTest.cpp">
</File>
</Filter>
</Filter>
<Filter
Name="_Suite"
Filter="">
<Filter
Name="Header Files"
Filter="">
<File
RelativePath=".\src\ZipTestSuite.h">
</File>
</Filter>
<Filter
Name="Source Files"
Filter="">
<File
RelativePath=".\src\ZipTestSuite.cpp">
</File>
</Filter>
</Filter>
<Filter
Name="_Driver"
Filter="">
<Filter
Name="Source Files"
Filter="">
<File
RelativePath=".\src\WinDriver.cpp">
</File>
</Filter>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,267 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Name="TestSuite"
ProjectGUID="{9665FC3C-DB71-4C6C-AAEE-AAFD73CB31E7}"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\include;..\..\Foundation\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;..\..\Net\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
BufferSecurityCheck="true"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="CppUnitd.lib WinTestRunnerd.lib PocoFoundationd.lib PocoZipd.lib PocoNetd.lib"
OutputFile="bin/TestSuited.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\lib"
GenerateDebugInformation="true"
ProgramDatabaseFile="bin/TestSuited.pdb"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="release_shared|Win32"
OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="4"
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories="..\include;..\..\Foundation\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;..\..\Net\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
StringPooling="true"
RuntimeLibrary="2"
BufferSecurityCheck="false"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="CppUnit.lib WinTestRunner.lib PocoFoundation.lib PocoZip.lib PocoNet.lib"
OutputFile="bin/TestSuite.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\lib"
GenerateDebugInformation="false"
ProgramDatabaseFile=""
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Zip"
>
<Filter
Name="Header Files"
>
<File
RelativePath=".\src\CompressTest.h"
>
</File>
<File
RelativePath=".\src\PartialStreamTest.h"
>
</File>
<File
RelativePath=".\src\ZipTest.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\CompressTest.cpp"
>
</File>
<File
RelativePath=".\src\PartialStreamTest.cpp"
>
</File>
<File
RelativePath=".\src\ZipTest.cpp"
>
</File>
</Filter>
</Filter>
<Filter
Name="_Suite"
>
<Filter
Name="Header Files"
>
<File
RelativePath=".\src\ZipTestSuite.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\ZipTestSuite.cpp"
>
</File>
</Filter>
</Filter>
<Filter
Name="_Driver"
>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\WinDriver.cpp"
>
</File>
</Filter>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,267 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="TestSuite"
ProjectGUID="{9665FC3C-DB71-4C6C-AAEE-AAFD73CB31E7}"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\include;..\..\Foundation\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;..\..\Net\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
BufferSecurityCheck="true"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="CppUnitd.lib WinTestRunnerd.lib PocoFoundationd.lib PocoZipd.lib PocoNetd.lib"
OutputFile="bin/TestSuited.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\lib"
GenerateDebugInformation="true"
ProgramDatabaseFile="bin/TestSuited.pdb"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="release_shared|Win32"
OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="4"
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories="..\include;..\..\Foundation\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;..\..\Net\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
StringPooling="true"
RuntimeLibrary="2"
BufferSecurityCheck="false"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="CppUnit.lib WinTestRunner.lib PocoFoundation.lib PocoZip.lib PocoNet.lib"
OutputFile="bin/TestSuite.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\lib"
GenerateDebugInformation="false"
ProgramDatabaseFile=""
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Zip"
>
<Filter
Name="Header Files"
>
<File
RelativePath=".\src\CompressTest.h"
>
</File>
<File
RelativePath=".\src\PartialStreamTest.h"
>
</File>
<File
RelativePath=".\src\ZipTest.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\CompressTest.cpp"
>
</File>
<File
RelativePath=".\src\PartialStreamTest.cpp"
>
</File>
<File
RelativePath=".\src\ZipTest.cpp"
>
</File>
</Filter>
</Filter>
<Filter
Name="_Suite"
>
<Filter
Name="Header Files"
>
<File
RelativePath=".\src\ZipTestSuite.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\ZipTestSuite.cpp"
>
</File>
</Filter>
</Filter>
<Filter
Name="_Driver"
>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\WinDriver.cpp"
>
</File>
</Filter>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

BIN
Zip/testsuite/data/data.zip Normal file

Binary file not shown.

BIN
Zip/testsuite/data/doc.zip Normal file

Binary file not shown.

BIN
Zip/testsuite/data/java.zip Normal file

Binary file not shown.

BIN
Zip/testsuite/data/test.zip Normal file

Binary file not shown.

View File

@ -0,0 +1,165 @@
//
// CompressTest.cpp
//
// $Id: //poco/1.3/Zip/testsuite/src/CompressTest.cpp#5 $
//
// 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.
//
#include "CompressTest.h"
#include "ZipTest.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>
using namespace Poco::Zip;
CompressTest::CompressTest(const std::string& name): CppUnit::TestCase(name)
{
}
CompressTest::~CompressTest()
{
}
void CompressTest::testSingleFile()
{
std::ofstream out("appinf.zip", std::ios::binary);
Poco::Path theFile(ZipTest::getTestFile("test.zip"));
Compress c(out, true);
c.addFile(theFile, theFile.getFileName());
ZipArchive a(c.close());
}
void CompressTest::testDirectory()
{
std::ofstream out("pocobin.zip", std::ios::binary);
Poco::File aFile("some/");
if (aFile.exists())
aFile.remove(true);
Poco::File aDir("some/recursive/dir/");
aDir.createDirectories();
Poco::File aDir2("some/other/recursive/dir/");
aDir2.createDirectories();
Poco::File aF("some/recursive/dir/test.file");
aF.createFile();
Poco::FileOutputStream fos(aF.path());
fos << "just some test data";
fos.close();
Poco::Path theFile(aFile.path());
theFile.makeDirectory();
Compress c(out, true);
c.addRecursive(theFile, ZipCommon::CL_MAXIMUM, false, theFile);
ZipArchive a(c.close());
}
void CompressTest::testManipulator()
{
{
std::ofstream out("appinf.zip", std::ios::binary);
Poco::Path theFile(ZipTest::getTestFile("test.zip"));
Compress c(out, true);
c.addFile(theFile, theFile.getFileName());
ZipArchive a(c.close());
}
ZipManipulator zm("appinf.zip", true);
zm.renameFile("test.zip", "renamedtest.zip");
zm.addFile("doc/othertest.zip", ZipTest::getTestFile("test.zip"));
ZipArchive archive=zm.commit();
assert (archive.findHeader("doc/othertest.zip") != archive.headerEnd());
}
void CompressTest::testManipulatorDel()
{
{
std::ofstream out("appinf.zip", std::ios::binary);
Poco::Path theFile(ZipTest::getTestFile("test.zip"));
Compress c(out, true);
c.addFile(theFile, theFile.getFileName());
ZipArchive a(c.close());
}
ZipManipulator zm("appinf.zip", true);
zm.deleteFile("test.zip");
zm.addFile("doc/data.zip", ZipTest::getTestFile("data.zip"));
ZipArchive archive=zm.commit();
assert (archive.findHeader("test.zip") == archive.headerEnd());
assert (archive.findHeader("doc/data.zip") != archive.headerEnd());
}
void CompressTest::testManipulatorReplace()
{
{
std::ofstream out("appinf.zip", std::ios::binary);
Poco::Path theFile(ZipTest::getTestFile("test.zip"));
Compress c(out, true);
c.addFile(theFile, theFile.getFileName());
ZipArchive a(c.close());
}
ZipManipulator zm("appinf.zip", true);
zm.replaceFile("test.zip", ZipTest::getTestFile("doc.zip"));
ZipArchive archive=zm.commit();
assert (archive.findHeader("test.zip") != archive.headerEnd());
assert (archive.findHeader("doc.zip") == archive.headerEnd());
}
void CompressTest::setUp()
{
}
void CompressTest::tearDown()
{
}
CppUnit::Test* CompressTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("CompressTest");
CppUnit_addTest(pSuite, CompressTest, testSingleFile);
CppUnit_addTest(pSuite, CompressTest, testDirectory);
CppUnit_addTest(pSuite, CompressTest, testManipulator);
CppUnit_addTest(pSuite, CompressTest, testManipulatorDel);
CppUnit_addTest(pSuite, CompressTest, testManipulatorReplace);
return pSuite;
}

View File

@ -0,0 +1,64 @@
//
// CompressTest.h
//
// $Id: //poco/1.3/Zip/testsuite/src/CompressTest.h#4 $
//
// Definition of the CompressTest class.
//
// 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.
//
#ifndef CompressTest_INCLUDED
#define CompressTest_INCLUDED
#include "Poco/Zip/Zip.h"
#include "CppUnit/TestCase.h"
class CompressTest: public CppUnit::TestCase
{
public:
CompressTest(const std::string& name);
~CompressTest();
void testSingleFile();
void testDirectory();
void testManipulator();
void testManipulatorDel();
void testManipulatorReplace();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // CompressTest_INCLUDED

View File

@ -0,0 +1,39 @@
//
// Driver.cpp
//
// $Id: //poco/1.3/Zip/testsuite/src/Driver.cpp#2 $
//
// Console-based test driver for Poco Zip.
//
// 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.
//
#include "CppUnit/TestRunner.h"
#include "ZipTestSuite.h"
CppUnitMain(ZipTestSuite)

View File

@ -0,0 +1,139 @@
//
// PartialStreamTest.cpp
//
// $Id: //poco/1.3/Zip/testsuite/src/PartialStreamTest.cpp#3 $
//
// 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.
//
#include "PartialStreamTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/Zip/PartialStream.h"
#include <sstream>
using namespace Poco::Zip;
PartialStreamTest::PartialStreamTest(const std::string& name): CppUnit::TestCase(name)
{
}
PartialStreamTest::~PartialStreamTest()
{
}
void PartialStreamTest::testReading()
{
std::string message("some dummy message !");
std::string prefix("pre ");
std::string postfix(" post");
std::string result(prefix+message+postfix);
std::istringstream istr(message);
PartialInputStream in(istr, 0, static_cast<std::streamoff>(message.length()), true, prefix, postfix);
char buf[124];
in.read(buf, 124);
std::string res(buf, in.gcount());
poco_assert (res == result);
}
void PartialStreamTest::testWriting()
{
std::string prefix("X");
std::string message("some test message");
std::string postfix("YYY");
std::string result(prefix+message+postfix);
std::ostringstream ostr;
PartialOutputStream out(ostr, prefix.size(), postfix.size());
out.write(result.c_str(), static_cast<std::streamsize>(result.length()));
poco_assert (out.good());
out.close();
std::string res (ostr.str());
poco_assert (out.bytesWritten() == message.size());
poco_assert (message == res);
}
void PartialStreamTest::testWritingZero()
{
std::string prefix("X");
std::string message;
std::string postfix("YYY");
std::string result(prefix+message+postfix);
std::ostringstream ostr;
PartialOutputStream out(ostr, prefix.size(), postfix.size());
out.write(result.c_str(), static_cast<std::streamsize>(result.length()));
poco_assert (out.good());
out.close();
std::string res (ostr.str());
poco_assert (out.bytesWritten() == message.size());
poco_assert (message == res);
}
void PartialStreamTest::testWritingOne()
{
std::string prefix("X");
std::string message("a");
std::string postfix("YYY");
std::string result(prefix+message+postfix);
std::ostringstream ostr;
PartialOutputStream out(ostr, prefix.size(), postfix.size());
out.write(result.c_str(), static_cast<std::streamsize>(result.length()));
poco_assert (out.good());
out.close();
std::string res (ostr.str());
poco_assert (out.bytesWritten() == message.size());
poco_assert (message == res);
}
void PartialStreamTest::setUp()
{
}
void PartialStreamTest::tearDown()
{
}
CppUnit::Test* PartialStreamTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("PartialStreamTest");
CppUnit_addTest(pSuite, PartialStreamTest, testReading);
CppUnit_addTest(pSuite, PartialStreamTest, testWriting);
CppUnit_addTest(pSuite, PartialStreamTest, testWritingZero);
CppUnit_addTest(pSuite, PartialStreamTest, testWritingOne);
return pSuite;
}

View File

@ -0,0 +1,63 @@
//
// PartialStreamTest.h
//
// $Id: //poco/1.3/Zip/testsuite/src/PartialStreamTest.h#3 $
//
// Definition of the PartialStreamTest class.
//
// 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.
//
#ifndef PartialStreamTest_INCLUDED
#define PartialStreamTest_INCLUDED
#include "Poco/Zip/Zip.h"
#include "CppUnit/TestCase.h"
class PartialStreamTest: public CppUnit::TestCase
{
public:
PartialStreamTest(const std::string& name);
~PartialStreamTest();
void testReading();
void testWriting();
void testWritingZero();
void testWritingOne();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // PartialStreamTest_INCLUDED

View File

@ -0,0 +1,50 @@
//
// WinDriver.cpp
//
// $Id: //poco/1.3/Zip/testsuite/src/WinDriver.cpp#2 $
//
// Windows test driver for Poco Zip.
//
// 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.
//
#include "WinTestRunner/WinTestRunner.h"
#include "ZipTestSuite.h"
class TestDriver: public CppUnit::WinTestRunnerApp
{
void TestMain()
{
CppUnit::WinTestRunner runner;
runner.addTest(ZipTestSuite::suite());
runner.run();
}
};
TestDriver theDriver;

View File

@ -0,0 +1,286 @@
//
// ZipTest.cpp
//
// $Id: //poco/1.3/Zip/testsuite/src/ZipTest.cpp#6 $
//
// 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.
//
#include "ZipTest.h"
#include "Poco/Zip/SkipCallback.h"
#include "Poco/Zip/ZipLocalFileHeader.h"
#include "Poco/Zip/ZipArchive.h"
#include "Poco/Zip/ZipStream.h"
#include "Poco/Zip/Decompress.h"
#include "Poco/StreamCopier.h"
#include "Poco/File.h"
#include "Poco/URI.h"
#include "Poco/Path.h"
#include "Poco/Delegate.h"
#include "Poco/Net/HTTPClientSession.h"
#include "Poco/Net/HTTPRequest.h"
#include "Poco/Net/HTTPResponse.h"
#include "Poco/Net/HTTPServer.h"
#include "Poco/Net/HTTPServerParams.h"
#include "Poco/Net/AbstractHTTPRequestHandler.h"
#include "Poco/Net/HTTPRequestHandlerFactory.h"
#include "Poco/Net/HTTPServerRequest.h"
#include "Poco/Net/HTTPServerResponse.h"
#include "Poco/Net/ServerSocket.h"
#include "Poco/StreamCopier.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include <fstream>
#include <sstream>
using namespace Poco::Zip;
using namespace Poco::Net;
namespace
{
class ZipFileRequestHandler: public HTTPRequestHandler
{
public:
ZipFileRequestHandler()
{
}
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
{
response.setChunkedTransferEncoding(true);
std::string testFile = ZipTest::getTestFile("test.zip");
std::ifstream inp(testFile.c_str(), std::ios::binary);
poco_assert (inp);
response.setContentType("application/zip");
std::ostream& ostr = response.send();
Poco::StreamCopier::copyStream(inp, ostr);
}
};
class RequestHandlerFactory: public HTTPRequestHandlerFactory
{
public:
HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request)
{
if (request.getURI() == "/test.zip")
return new ZipFileRequestHandler;
else
return 0;
}
};
}
ZipTest::ZipTest(const std::string& name): CppUnit::TestCase(name)
{
}
ZipTest::~ZipTest()
{
}
void ZipTest::testSkipSingleFile()
{
std::string testFile = getTestFile("test.zip");
std::ifstream inp(testFile.c_str(), std::ios::binary);
poco_assert (inp);
SkipCallback skip;
ZipLocalFileHeader hdr(inp, false, skip);
poco_assert (ZipCommon::HS_FAT == hdr.getHostSystem());
int major = hdr.getMajorVersionNumber();
int minor = hdr.getMinorVersionNumber();
poco_assert (major <= 2);
std::size_t hdrSize = hdr.getHeaderSize();
poco_assert (hdrSize > 30);
ZipCommon::CompressionMethod cm = hdr.getCompressionMethod();
poco_assert (!hdr.isEncrypted());
Poco::DateTime aDate = hdr.lastModifiedAt();
Poco::UInt32 cS = hdr.getCompressedSize();
Poco::UInt32 uS = hdr.getUncompressedSize();
const std::string& fileName = hdr.getFileName();
}
void ZipTest::testDecompressSingleFile()
{
std::string testFile = getTestFile("test.zip");
std::ifstream inp(testFile.c_str(), std::ios::binary);
poco_assert (inp);
ZipArchive arch(inp);
ZipArchive::FileHeaders::const_iterator it = arch.findHeader("Zip_VS71.vcproj");
poco_assert (it != arch.headerEnd());
ZipInputStream zipin (inp, it->second);
std::ostringstream out(std::ios::binary);
Poco::StreamCopier::copyStream(zipin, out);
poco_assert(!out.str().empty());
}
void ZipTest::testCrcAndSizeAfterData()
{
std::string testFile = getTestFile("java.zip");
std::ifstream inp(testFile.c_str(), std::ios::binary);
poco_assert (inp);
Decompress dec(inp, Poco::Path());
dec.EError += Poco::Delegate<ZipTest, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string> >(this, &ZipTest::onDecompressError);
dec.decompressAllFiles();
dec.EError -= Poco::Delegate<ZipTest, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string> >(this, &ZipTest::onDecompressError);
poco_assert (_errCnt == 0);
poco_assert (!dec.mapping().empty());
}
void ZipTest::testCrcAndSizeAfterDataWithArchive()
{
std::string testFile = getTestFile("java.zip");
std::ifstream inp(testFile.c_str(), std::ios::binary);
poco_assert (inp);
Poco::Zip::ZipArchive zip(inp);
inp.clear();
inp.seekg(0);
Poco::Zip::ZipArchive::FileHeaders::const_iterator it = zip.headerBegin();
for ( ; it!=zip.headerEnd(); ++it)
{
Poco::Zip::ZipInputStream zipis(inp,it->second);
Poco::Path path(it->second.getFileName());
if (path.isFile())
{
std::ofstream os("test.dat");
Poco::StreamCopier::copyStream(zipis,os);
}
}
}
std::string ZipTest::getTestFile(const std::string& testFile)
{
Poco::Path root;
root.makeAbsolute();
Poco::Path result;
while (!Poco::Path::find(root.toString(), "data", result))
{
root.makeParent();
if (root.toString().empty() || root.toString() == "/")
throw Poco::FileNotFoundException("Didn't find data subdir");
}
result.makeDirectory();
result.setFileName(testFile);
Poco::File aFile(result.toString());
if (!aFile.exists() || (aFile.exists() && !aFile.isFile()))
throw Poco::FileNotFoundException("Didn't find " + testFile);
return result.toString();
}
void ZipTest::testDecompress()
{
std::string testFile = getTestFile("test.zip");
std::ifstream inp(testFile.c_str(), std::ios::binary);
poco_assert (inp);
Decompress dec(inp, Poco::Path());
dec.EError += Poco::Delegate<ZipTest, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string> >(this, &ZipTest::onDecompressError);
dec.decompressAllFiles();
dec.EError -= Poco::Delegate<ZipTest, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string> >(this, &ZipTest::onDecompressError);
poco_assert (_errCnt == 0);
poco_assert (!dec.mapping().empty());
}
void ZipTest::testDecompressFlat()
{
std::string testFile = getTestFile("test.zip");
std::ifstream inp(testFile.c_str(), std::ios::binary);
poco_assert (inp);
Decompress dec(inp, Poco::Path(), true);
dec.EError += Poco::Delegate<ZipTest, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string> >(this, &ZipTest::onDecompressError);
dec.decompressAllFiles();
dec.EError -= Poco::Delegate<ZipTest, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string> >(this, &ZipTest::onDecompressError);
poco_assert (_errCnt == 0);
poco_assert (!dec.mapping().empty());
}
void ZipTest::decompressDirectlyFromNet()
{
ServerSocket svs(22222);
HTTPServerParams* pParams = new HTTPServerParams;
pParams->setKeepAlive(true);
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
srv.start();
Poco::URI uri("http://localhost:22222/test.zip");
HTTPClientSession session("localhost", 22222);
HTTPRequest req(HTTPRequest::HTTP_GET, "/test.zip", HTTPMessage::HTTP_1_1);
session.sendRequest(req);
HTTPResponse res;
std::istream& rs = session.receiveResponse(res);
Decompress dec(rs, Poco::Path());
dec.EError += Poco::Delegate<ZipTest, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string> >(this, &ZipTest::onDecompressError);
dec.decompressAllFiles();
dec.EError -= Poco::Delegate<ZipTest, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string> >(this, &ZipTest::onDecompressError);
poco_assert (_errCnt == 0);
poco_assert (!dec.mapping().empty());
}
void ZipTest::onDecompressError(const void* pSender, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string>& info)
{
++_errCnt;
}
void ZipTest::setUp()
{
_errCnt = 0;
}
void ZipTest::tearDown()
{
}
CppUnit::Test* ZipTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ZipTest");
CppUnit_addTest(pSuite, ZipTest, testSkipSingleFile);
CppUnit_addTest(pSuite, ZipTest, testDecompressSingleFile);
CppUnit_addTest(pSuite, ZipTest, testDecompress);
CppUnit_addTest(pSuite, ZipTest, testDecompressFlat);
CppUnit_addTest(pSuite, ZipTest, decompressDirectlyFromNet);
CppUnit_addTest(pSuite, ZipTest, testCrcAndSizeAfterData);
CppUnit_addTest(pSuite, ZipTest, testCrcAndSizeAfterDataWithArchive);
return pSuite;
}

View File

@ -0,0 +1,73 @@
//
// ZipTest.h
//
// $Id: //poco/1.3/Zip/testsuite/src/ZipTest.h#5 $
//
// Definition of the ZipTest class.
//
// 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.
//
#ifndef ZipTest_INCLUDED
#define ZipTest_INCLUDED
#include "Poco/Zip/Zip.h"
#include "Poco/Zip/ZipLocalFileHeader.h"
#include "CppUnit/TestCase.h"
class ZipTest: public CppUnit::TestCase
{
public:
ZipTest(const std::string& name);
~ZipTest();
void testSkipSingleFile();
void testDecompressSingleFile();
void testDecompress();
void decompressDirectlyFromNet();
void testCrcAndSizeAfterData();
void testCrcAndSizeAfterDataWithArchive();
void testDecompressFlat();
void setUp();
void tearDown();
static CppUnit::Test* suite();
static std::string getTestFile(const std::string& testFile);
private:
void onDecompressError(const void* pSender, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string>& info);
int _errCnt;
};
#endif // ZipTest_INCLUDED

View File

@ -0,0 +1,48 @@
//
// ZipTestSuite.cpp
//
// $Id: //poco/1.3/Zip/testsuite/src/ZipTestSuite.cpp#1 $
//
// Copyright (c) 2006, 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.
//
#include "ZipTestSuite.h"
#include "ZipTest.h"
#include "PartialStreamTest.h"
#include "CompressTest.h"
CppUnit::Test* ZipTestSuite::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ZipTestSuite");
pSuite->addTest(ZipTest::suite());
pSuite->addTest(PartialStreamTest::suite());
pSuite->addTest(CompressTest::suite());
return pSuite;
}

View File

@ -0,0 +1,49 @@
//
// ZipTestSuite.h
//
// $Id: //poco/1.3/Zip/testsuite/src/ZipTestSuite.h#1 $
//
// Definition of the ZipTestSuite class.
//
// Copyright (c) 2006, 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.
//
#ifndef ZipTestSuite_INCLUDED
#define ZipTestSuite_INCLUDED
#include "CppUnit/TestSuite.h"
class ZipTestSuite
{
public:
static CppUnit::Test* suite();
};
#endif // ZipTestSuite_INCLUDED