source upload
This commit is contained in:
23
contrib/grittibanzli/CONTRIBUTING.md
Normal file
23
contrib/grittibanzli/CONTRIBUTING.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# How to Contribute
|
||||
|
||||
We'd love to accept your patches and contributions to this project. There are
|
||||
just a few small guidelines you need to follow.
|
||||
|
||||
## Contributor License Agreement
|
||||
|
||||
Contributions to this project must be accompanied by a Contributor License
|
||||
Agreement. You (or your employer) retain the copyright to your contribution,
|
||||
this simply gives us permission to use and redistribute your contributions as
|
||||
part of the project. Head over to <https://cla.developers.google.com/> to see
|
||||
your current agreements on file or to sign a new one.
|
||||
|
||||
You generally only need to submit a CLA once, so if you've already submitted one
|
||||
(even if it was for a different project), you probably don't need to do it
|
||||
again.
|
||||
|
||||
## Code reviews
|
||||
|
||||
All submissions, including submissions by project members, require review. We
|
||||
use GitHub pull requests for this purpose. Consult
|
||||
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
|
||||
information on using pull requests.
|
202
contrib/grittibanzli/LICENSE
Normal file
202
contrib/grittibanzli/LICENSE
Normal file
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
9
contrib/grittibanzli/Makefile
Normal file
9
contrib/grittibanzli/Makefile
Normal file
@@ -0,0 +1,9 @@
|
||||
CXX = g++
|
||||
|
||||
CXXFLAGS := -std=c++11 -W -Wall -Wextra -O2 $(CXXFLAGS)
|
||||
|
||||
.PHONY: grittibanzli
|
||||
|
||||
# grittibanzli binary tool
|
||||
grittibanzli:
|
||||
$(CXX) main.cc grittibanzli.cc $(CXXFLAGS) -o grittibanzli
|
32
contrib/grittibanzli/README.md
Normal file
32
contrib/grittibanzli/README.md
Normal file
@@ -0,0 +1,32 @@
|
||||
Grittibanzli is a tool to compress a deflate stream to a smaller file, which can
|
||||
be decoded to the original deflate stream again. That is, it compresses not only
|
||||
the data inside the deflate stream, but also the deflate-related information
|
||||
such as LZ77 symbols and Huffman trees, to reproduce a gzip, png, ... file
|
||||
exactly.
|
||||
|
||||
Usually compressing a compressed file does not work well, and Grittibanzli aims
|
||||
to improve this situation for compressing deflate files.
|
||||
|
||||
Grittibanzli splits a deflate container into 2 or 3 streams:
|
||||
-uncompressed data: the original data
|
||||
-deflate choices needed to reproduce the exact deflate stream. It uses
|
||||
prediction to encode it well no matter what deflate compressor (gzip -1 to -9,
|
||||
zopfli, ...) was used. The prediction works best for gzip -6 to -9.
|
||||
-when applicable: container metadata (such as gzip header)
|
||||
|
||||
These different byte streams then need to be compressed to produce a new file
|
||||
smaller than the original deflate container. Suggested compression algorithms:
|
||||
|
||||
-uncompressed data: Brotli quality 11
|
||||
-deflate choices: PPMd, or Brotli quality 10 or 11
|
||||
-metadata: Brotli quality 11
|
||||
|
||||
Well compressed choices will be roughly 0.5-1% for gzip -6 to -9, 9% for zopfli,
|
||||
21% for gzip -1. As long as this percentage is smaller than the gain from
|
||||
Brotli-compressing the rest, the deflate container can be losslessly reduced.
|
||||
|
||||
Performing the compression is not included in this API. Grittibanzli's main
|
||||
result is the deflate choices bytestream, which is large but has a lot of
|
||||
zeroes so that you can compress it well.
|
||||
|
||||
This is not an official Google product.
|
1591
contrib/grittibanzli/grittibanzli.cc
Normal file
1591
contrib/grittibanzli/grittibanzli.cc
Normal file
File diff suppressed because it is too large
Load Diff
44
contrib/grittibanzli/grittibanzli.h
Normal file
44
contrib/grittibanzli/grittibanzli.h
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright 2018 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef GRITTIBANZLI_H_
|
||||
#define GRITTIBANZLI_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace grittibanzli {
|
||||
|
||||
// Splits a deflate stream into the uncompressed data inside, and, choices data
|
||||
// from which the original deflate stream (with same LZ77 lengths and so on)
|
||||
// can be reconstructed. The predicted choices stream is large but has a lot
|
||||
// of zeroes so it is very compressible.
|
||||
// After use, compress both the encoded choices and the original data with a
|
||||
// stronger compressor to achieve total filesize smaller than the original
|
||||
// deflate file.
|
||||
bool Grittibanzli(const uint8_t* deflated, size_t deflated_size,
|
||||
std::vector<uint8_t>* uncompressed,
|
||||
std::vector<uint8_t>* choices_encoded);
|
||||
|
||||
// Reconstructs the deflate stream from the uncompressed data and encoded
|
||||
// choices. Appends to deflated if not empty.
|
||||
bool Ungrittibanzli(const uint8_t* uncompressed, size_t uncompressed_size,
|
||||
const uint8_t* choices_encoded, size_t choices_size,
|
||||
std::vector<uint8_t>* deflated);
|
||||
|
||||
} // namespace grittibanzli
|
||||
|
||||
#endif // GRITTIBANZLI_H_
|
65
contrib/grittibanzli/grittibanzli_dll/dllmain.cpp
Normal file
65
contrib/grittibanzli/grittibanzli_dll/dllmain.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
// dllmain.cpp : Defines the entry point for the DLL application.
|
||||
#include "pch.h"
|
||||
#include <algorithm>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <cstdint>
|
||||
#include <iterator>
|
||||
#include <vector>
|
||||
#include "..\grittibanzli.h"
|
||||
|
||||
BOOL APIENTRY DllMain( HMODULE hModule,
|
||||
DWORD ul_reason_for_call,
|
||||
LPVOID lpReserved
|
||||
)
|
||||
{
|
||||
switch (ul_reason_for_call)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
case DLL_THREAD_ATTACH:
|
||||
case DLL_THREAD_DETACH:
|
||||
case DLL_PROCESS_DETACH:
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
namespace grittibanzli {
|
||||
|
||||
extern "C" __declspec(dllexport) bool __Grittibanzli(const uint8_t* src,
|
||||
size_t srcSize, uint8_t* dst1, size_t* dst1Capacity, uint8_t* dst2,
|
||||
size_t* dst2Capacity) {
|
||||
std::vector<uint8_t>uncompressed;
|
||||
std::vector<uint8_t>choices_encoded;
|
||||
if ((Grittibanzli(src, srcSize, &uncompressed, &choices_encoded) == true) && (uncompressed.size() <= *dst1Capacity)
|
||||
&& (choices_encoded.size() <= *dst2Capacity)) {
|
||||
*dst1Capacity = uncompressed.size();
|
||||
memcpy(dst1, uncompressed.data(), uncompressed.size());
|
||||
*dst2Capacity = choices_encoded.size();
|
||||
memcpy(dst2, choices_encoded.data(), choices_encoded.size());
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) bool __Ungrittibanzli(const uint8_t* src1,
|
||||
size_t src1Size, const unsigned char* src2,
|
||||
size_t src2Size, unsigned char* dst, size_t* dstCapacity) {
|
||||
std::vector<uint8_t>deflated;
|
||||
if ((Ungrittibanzli(src1, src1Size, src2, src2Size, &deflated) == true) && (deflated.size() <= *dstCapacity)) {
|
||||
*dstCapacity = deflated.size();
|
||||
memcpy(dst, deflated.data(), deflated.size());
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
5
contrib/grittibanzli/grittibanzli_dll/framework.h
Normal file
5
contrib/grittibanzli/grittibanzli_dll/framework.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||
// Windows Header Files
|
||||
#include <windows.h>
|
31
contrib/grittibanzli/grittibanzli_dll/grittibanzli_dll.sln
Normal file
31
contrib/grittibanzli/grittibanzli_dll/grittibanzli_dll.sln
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.30204.135
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grittibanzli_dll", "grittibanzli_dll.vcxproj", "{18F8C4F5-C51A-46B6-B0AB-9504B357B4D5}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{18F8C4F5-C51A-46B6-B0AB-9504B357B4D5}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{18F8C4F5-C51A-46B6-B0AB-9504B357B4D5}.Debug|x64.Build.0 = Debug|x64
|
||||
{18F8C4F5-C51A-46B6-B0AB-9504B357B4D5}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{18F8C4F5-C51A-46B6-B0AB-9504B357B4D5}.Debug|x86.Build.0 = Debug|Win32
|
||||
{18F8C4F5-C51A-46B6-B0AB-9504B357B4D5}.Release|x64.ActiveCfg = Release|x64
|
||||
{18F8C4F5-C51A-46B6-B0AB-9504B357B4D5}.Release|x64.Build.0 = Release|x64
|
||||
{18F8C4F5-C51A-46B6-B0AB-9504B357B4D5}.Release|x86.ActiveCfg = Release|Win32
|
||||
{18F8C4F5-C51A-46B6-B0AB-9504B357B4D5}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {D2002999-777B-44DA-8304-BA0D324C6297}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
174
contrib/grittibanzli/grittibanzli_dll/grittibanzli_dll.vcxproj
Normal file
174
contrib/grittibanzli/grittibanzli_dll/grittibanzli_dll.vcxproj
Normal file
@@ -0,0 +1,174 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{18f8c4f5-c51a-46b6-b0ab-9504b357b4d5}</ProjectGuid>
|
||||
<RootNamespace>grittibanzlidll</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;GRITTIBANZLIDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;GRITTIBANZLIDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;GRITTIBANZLIDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;GRITTIBANZLIDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<Optimization>Full</Optimization>
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\grittibanzli.h" />
|
||||
<ClInclude Include="framework.h" />
|
||||
<ClInclude Include="pch.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\grittibanzli.cc" />
|
||||
<ClCompile Include="dllmain.cpp" />
|
||||
<ClCompile Include="pch.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="framework.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="pch.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\grittibanzli.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="dllmain.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="pch.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\grittibanzli.cc">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
</Project>
|
5
contrib/grittibanzli/grittibanzli_dll/pch.cpp
Normal file
5
contrib/grittibanzli/grittibanzli_dll/pch.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
// pch.cpp: source file corresponding to the pre-compiled header
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
// When you are using pre-compiled headers, this source file is necessary for compilation to succeed.
|
13
contrib/grittibanzli/grittibanzli_dll/pch.h
Normal file
13
contrib/grittibanzli/grittibanzli_dll/pch.h
Normal file
@@ -0,0 +1,13 @@
|
||||
// pch.h: This is a precompiled header file.
|
||||
// Files listed below are compiled only once, improving build performance for future builds.
|
||||
// This also affects IntelliSense performance, including code completion and many code browsing features.
|
||||
// However, files listed here are ALL re-compiled if any one of them is updated between builds.
|
||||
// Do not add files here that you will be updating frequently as this negates the performance advantage.
|
||||
|
||||
#ifndef PCH_H
|
||||
#define PCH_H
|
||||
|
||||
// add headers that you want to pre-compile here
|
||||
#include "framework.h"
|
||||
|
||||
#endif //PCH_H
|
344
contrib/grittibanzli/main.cc
Normal file
344
contrib/grittibanzli/main.cc
Normal file
@@ -0,0 +1,344 @@
|
||||
// Copyright 2018 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// This is an example binary using grittibanzli, supporting pure deflate and
|
||||
// gzip formats.
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
#include "grittibanzli.h"
|
||||
|
||||
namespace grittibanzli {
|
||||
|
||||
namespace {
|
||||
// Returns true iff the file exists and is readable
|
||||
bool FileExists(const std::string& filename) {
|
||||
FILE* file = fopen(filename.c_str(), "rb");
|
||||
bool result = (file != 0);
|
||||
if (file) fclose(file);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Returns -1 on error, such as when file doesn't exist
|
||||
int64_t GetFileSize(const std::string& filename) {
|
||||
FILE* file = fopen(filename.c_str(), "rb");
|
||||
if (!file) return -1;
|
||||
if (fseek(file, 0, SEEK_END) != 0) {
|
||||
fclose(file);
|
||||
return -1;
|
||||
}
|
||||
int64_t size = ftell(file);
|
||||
if (size == LONG_MAX) size = -1;
|
||||
fclose(file);
|
||||
return size;
|
||||
}
|
||||
|
||||
bool LoadFile(const std::string& filename, std::vector<uint8_t>* result) {
|
||||
int64_t size = GetFileSize(filename);
|
||||
if (size < 0) return false;
|
||||
result->resize(size);
|
||||
if (size == 0) return true;
|
||||
|
||||
FILE* file = fopen(filename.c_str(), "rb");
|
||||
if (!file) return false;
|
||||
size_t readsize = fread(result->data(), 1, size, file);
|
||||
fclose(file);
|
||||
|
||||
if (readsize != static_cast<size_t>(size)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SaveFile(const std::vector<uint8_t>& data, const std::string& filename) {
|
||||
FILE* file = fopen(filename.c_str(), "wb" );
|
||||
if (!file) return false;
|
||||
fwrite((char*)data.data() , 1 , data.size(), file);
|
||||
fclose(file);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ParseGzipHeaders(const std::vector<uint8_t>& data,
|
||||
int* deflate_begin, int* deflate_end) {
|
||||
if (data.size() < 10) return false;
|
||||
int flag = data[3];
|
||||
size_t pos = 10;
|
||||
if (flag & 2) {
|
||||
if (pos + 2 <= data.size()) return false;
|
||||
// skip FEXTRA
|
||||
pos += data[pos] + 256 * data[pos + 1];
|
||||
}
|
||||
if (flag & 4) {
|
||||
// skip FNAME
|
||||
while (pos < data.size() && data[pos]) pos++;
|
||||
pos++;
|
||||
}
|
||||
if (flag & 8) {
|
||||
// skip FCOMMENT
|
||||
while (pos < data.size() && data[pos]) pos++;
|
||||
pos++;
|
||||
}
|
||||
if (pos + 8 >= data.size()) return false;
|
||||
*deflate_begin = pos;
|
||||
*deflate_end = data.size() - 8;
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void PrintHelp(const char* argv0) {
|
||||
std::cout << "Grittibanzli encodes all information needed to reconstruct "
|
||||
" a deflate compressed file (gz or pure deflate) into an easy"
|
||||
" to compress format\n"
|
||||
<< "Usage: " << argv0
|
||||
<< " [OPTIONS] [--input=FILENAME] [--output=FILENAME]"
|
||||
" [--data=FILENAME] [--choices=FILENAME] [--meta=FILENAME]\n"
|
||||
"Options:\n"
|
||||
" -d: decode instead of encode. decode = reconstruct gz file,"
|
||||
" encode = split gz file into data, compressible deflate choices"
|
||||
" and metadata\n"
|
||||
" -f: force to overwrite when output files already exist\n"
|
||||
" -h: show this help\n"
|
||||
" -q: quiet: don't print stats when compressing\n"
|
||||
" -v: verify after encoding or decoding\n"
|
||||
" --pure_deflate: use pure deflate instead of gzip\n"
|
||||
" --input: gz filename when encoding\n"
|
||||
" --output: gz filename when decoding\n"
|
||||
" --choices: encoded deflate choices filename.\n"
|
||||
" --data: uncompressed data filename.\n"
|
||||
" --meta: metadata filename (unused for pure_deflate).\n"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
void InvalidArgument(const char* argv0, const std::string& message = "") {
|
||||
std::cout << "Invalid Arguments" << message << std::endl;
|
||||
PrintHelp(argv0);
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
void DieWithError(const std::string& text) {
|
||||
std::cout << text << std::endl;
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
#define TryWithError(code, errortext) if (!(code)) DieWithError(errortext);
|
||||
|
||||
bool Encode(bool format_gzip, const std::vector<uint8_t>& in,
|
||||
std::vector<uint8_t>* data, std::vector<uint8_t>* choices,
|
||||
std::vector<uint8_t>* meta) {
|
||||
int start = 0, end = in.size();
|
||||
if (format_gzip) {
|
||||
TryWithError(ParseGzipHeaders(in, &start, &end), "Invalid gzip file");
|
||||
meta->assign(in.begin(), in.begin() + start);
|
||||
meta->insert(meta->end(), in.begin() + end, in.end());
|
||||
}
|
||||
|
||||
const uint8_t* deflate = in.data() + start;
|
||||
size_t deflate_size = end - start;
|
||||
return Grittibanzli(deflate, deflate_size, data, choices);
|
||||
}
|
||||
|
||||
bool Decode(bool format_gzip, const std::vector<uint8_t>& data,
|
||||
const std::vector<uint8_t>& choices, const std::vector<uint8_t>& meta,
|
||||
std::vector<uint8_t>* out) {
|
||||
if (format_gzip) {
|
||||
if (meta.size() < 8) DieWithError("Invalid gzip metadata");
|
||||
out->assign(meta.begin(), meta.end() - 8);
|
||||
}
|
||||
|
||||
if (!Ungrittibanzli(data.data(), data.size(),
|
||||
choices.data(), choices.size(), out)) return false;
|
||||
|
||||
if (format_gzip) {
|
||||
out->insert(out->end(), meta.end() - 8, meta.end());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int Run(int argc, char *argv[]) {
|
||||
bool decode = false;
|
||||
bool force = false;
|
||||
bool verbose = true;
|
||||
bool verify = false;
|
||||
bool format_gzip = true;
|
||||
std::string fname_input;
|
||||
std::string fname_output;
|
||||
std::string fname_choices;
|
||||
std::string fname_data;
|
||||
std::string fname_meta;
|
||||
for (int i = 1; i < argc; i++) {
|
||||
std::string arg(argv[i]);
|
||||
if (arg.size() < 2) InvalidArgument(argv[0]);
|
||||
|
||||
if (arg == "--pure_deflate") {
|
||||
format_gzip = false;
|
||||
} else if (arg[0] == '-' && arg[1] != '-') {
|
||||
for (size_t j = 1; j < arg.size(); j++) {
|
||||
if (arg[j] == 'd') {
|
||||
decode = true;
|
||||
} else if (arg[j] == 'f') {
|
||||
force = true;
|
||||
} else if (arg[j] == 'q') {
|
||||
verbose = false;
|
||||
} else if (arg[j] == 'v') {
|
||||
verify = true;
|
||||
} else if (arg[j] == 'h') {
|
||||
PrintHelp(argv[0]);
|
||||
return 0;
|
||||
} else {
|
||||
std::string unknown = " ";
|
||||
unknown[0] = arg[j];
|
||||
InvalidArgument(argv[0], ": unknown option " + unknown);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
size_t eq = arg.find('=');
|
||||
std::string key, value;
|
||||
if (eq == std::string::npos) {
|
||||
key = arg;
|
||||
if (i + 1 >= argc) InvalidArgument(argv[0]);
|
||||
value = argv[i + 1];
|
||||
i++;
|
||||
} else {
|
||||
key = arg.substr(0, eq);
|
||||
value = arg.substr(eq + 1);
|
||||
}
|
||||
if (value.empty()) InvalidArgument(argv[0]);
|
||||
if (key == "--input") {
|
||||
if (value.empty()) InvalidArgument(argv[0]);
|
||||
fname_input = value;
|
||||
} else if (key == "--output") {
|
||||
if (value.empty()) InvalidArgument(argv[0]);
|
||||
fname_output = value;
|
||||
} else if (key == "--choices") {
|
||||
if (value.empty()) InvalidArgument(argv[0]);
|
||||
fname_choices = value;
|
||||
} else if (key == "--data") {
|
||||
if (value.empty()) InvalidArgument(argv[0]);
|
||||
fname_data = value;
|
||||
} else if (key == "--meta") {
|
||||
if (value.empty()) InvalidArgument(argv[0]);
|
||||
fname_meta = value;
|
||||
} else {
|
||||
InvalidArgument(argv[0], ": unknown key " + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (decode) {
|
||||
if (fname_output.empty()) InvalidArgument(argv[0], ": --output missing");
|
||||
if (!fname_input.empty()) {
|
||||
InvalidArgument(argv[0], ": --input may not be given when decoding,"
|
||||
" use --choices, --data and --meta as inputs");
|
||||
}
|
||||
if (fname_choices.empty()) InvalidArgument(argv[0], ": --choices missing");
|
||||
if (fname_data.empty()) InvalidArgument(argv[0], ": --data missing");
|
||||
if (!format_gzip && fname_meta.empty()) {
|
||||
InvalidArgument(argv[0], ": --meta missing");
|
||||
}
|
||||
|
||||
if (!force && FileExists(fname_output)) {
|
||||
DieWithError(fname_output + " already exists");
|
||||
}
|
||||
|
||||
std::vector<uint8_t> data, choices, meta, out;
|
||||
TryWithError(LoadFile(fname_choices, &choices),
|
||||
"Could not load " + fname_choices);
|
||||
TryWithError(LoadFile(fname_data, &data), "Could not load " + fname_data);
|
||||
if (format_gzip) {
|
||||
TryWithError(LoadFile(fname_meta, &meta), "Could not load " + fname_meta);
|
||||
}
|
||||
|
||||
TryWithError(Decode(format_gzip, data, choices, meta, &out),
|
||||
"Failed to decode to " + fname_output);
|
||||
|
||||
if (verify) {
|
||||
std::vector<uint8_t> data2, choices2, meta2;
|
||||
if (!Encode(format_gzip, out, &data2, &choices2, &meta2)
|
||||
|| data2 != data) {
|
||||
DieWithError("Failed to verify " + fname_output);
|
||||
}
|
||||
}
|
||||
|
||||
TryWithError(SaveFile(out, fname_output),
|
||||
"Failed to save " + fname_output);
|
||||
} else {
|
||||
if (fname_input.empty()) InvalidArgument(argv[0], ": --input missing");
|
||||
if (!fname_output.empty()) {
|
||||
InvalidArgument(argv[0], ": --output may not be given when encoding,"
|
||||
" use --choices, --data and --meta as inputs");
|
||||
}
|
||||
if (!force && FileExists(fname_choices)) {
|
||||
DieWithError(fname_choices + " already exists");
|
||||
}
|
||||
if (!force && FileExists(fname_data)) {
|
||||
DieWithError(fname_data + " already exists");
|
||||
}
|
||||
if (!force && FileExists(fname_meta)) {
|
||||
DieWithError(fname_meta + " already exists");
|
||||
}
|
||||
|
||||
std::vector<uint8_t> in, data, choices, meta;
|
||||
if (!LoadFile(fname_input, &in)) {
|
||||
DieWithError("Could not load " + fname_input);
|
||||
}
|
||||
TryWithError(Encode(format_gzip, in, &data, &choices, &meta),
|
||||
"Failed to encode " + fname_input);
|
||||
|
||||
if (verify) {
|
||||
std::vector<uint8_t> in2;
|
||||
if (!Decode(format_gzip, data, choices, meta, &in2) || in2 != in) {
|
||||
DieWithError("Failed to verify " + fname_input);
|
||||
}
|
||||
}
|
||||
|
||||
if (!fname_data.empty()) {
|
||||
TryWithError(SaveFile(data, fname_data), "Failed to save " + fname_data);
|
||||
}
|
||||
if (!fname_choices.empty()) {
|
||||
TryWithError(SaveFile(choices, fname_choices),
|
||||
"Failed to save " + fname_choices);
|
||||
}
|
||||
if (format_gzip && !fname_meta.empty()) {
|
||||
TryWithError(SaveFile(meta, fname_meta), "Failed to save " + fname_meta);
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
int zeroes = 0;
|
||||
for (size_t i = 0; i < choices.size(); i++) {
|
||||
if (!choices[i]) zeroes++;
|
||||
}
|
||||
std::cout << "input size: " << in.size()
|
||||
<< ", uncompressed size: " << data.size()
|
||||
<< ", metadata size: " << meta.size()
|
||||
<< ", choices size: " << choices.size()
|
||||
<< " of which " << (choices.size() - zeroes) << " non-zeroes"
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
} // namespace grittibanzli
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
return grittibanzli::Run(argc, argv);
|
||||
}
|
Reference in New Issue
Block a user