|
1 |
| -// Copyright (c) Microsoft Corporation. |
2 |
| -// Licensed under the MIT License. |
3 |
| -#include "pch.h" |
4 |
| -#include "Public/winget/Compression.h" |
5 |
| - |
6 |
| -namespace AppInstaller::Compression |
7 |
| -{ |
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT License. |
| 3 | +#include "pch.h" |
| 4 | +#include "Public/winget/Compression.h" |
| 5 | + |
| 6 | +namespace AppInstaller::Compression |
| 7 | +{ |
8 | 8 | Compressor::Compressor(DWORD algorithm)
|
9 |
| - { |
10 |
| - THROW_IF_WIN32_BOOL_FALSE(CreateCompressor(algorithm, nullptr, &m_compressor)); |
11 |
| - } |
12 |
| - |
| 9 | + { |
| 10 | + THROW_IF_WIN32_BOOL_FALSE(CreateCompressor(algorithm, nullptr, &m_compressor)); |
| 11 | + } |
| 12 | + |
13 | 13 | std::vector<uint8_t> Compressor::Compress(std::string_view data)
|
14 | 14 | {
|
15 | 15 | std::vector<uint8_t> result;
|
16 | 16 |
|
17 | 17 | if (!data.empty())
|
18 |
| - { |
19 |
| - size_t compressedBufferSize = 0; |
| 18 | + { |
| 19 | + SIZE_T compressedBufferSize = 0; |
20 | 20 | THROW_HR_IF(E_UNEXPECTED, ::Compress(m_compressor.get(), data.data(), data.size(), nullptr, 0, &compressedBufferSize));
|
21 | 21 | THROW_LAST_ERROR_IF(GetLastError() != ERROR_INSUFFICIENT_BUFFER);
|
22 | 22 |
|
23 | 23 | result.resize(compressedBufferSize);
|
24 |
| - |
25 |
| - size_t compressedDataSize = 0; |
| 24 | + |
| 25 | + SIZE_T compressedDataSize = 0; |
26 | 26 | THROW_IF_WIN32_BOOL_FALSE(::Compress(m_compressor.get(), data.data(), data.size(), &result[0], result.size(), &compressedDataSize));
|
27 | 27 |
|
28 | 28 | result.resize(compressedDataSize);
|
29 | 29 | }
|
30 | 30 |
|
31 |
| - return result; |
32 |
| - } |
33 |
| - |
| 31 | + return result; |
| 32 | + } |
| 33 | + |
34 | 34 | void Compressor::Reset()
|
35 |
| - { |
36 |
| - THROW_IF_WIN32_BOOL_FALSE(ResetCompressor(m_compressor.get())); |
37 |
| - } |
38 |
| - |
| 35 | + { |
| 36 | + THROW_IF_WIN32_BOOL_FALSE(ResetCompressor(m_compressor.get())); |
| 37 | + } |
| 38 | + |
39 | 39 | void Compressor::SetInformation(COMPRESS_INFORMATION_CLASS information, DWORD value)
|
40 |
| - { |
41 |
| - THROW_IF_WIN32_BOOL_FALSE(SetCompressorInformation(m_compressor.get(), information, &value, sizeof(value))); |
42 |
| - } |
43 |
| - |
| 40 | + { |
| 41 | + THROW_IF_WIN32_BOOL_FALSE(SetCompressorInformation(m_compressor.get(), information, &value, sizeof(value))); |
| 42 | + } |
| 43 | + |
44 | 44 | DWORD Compressor::GetInformation(COMPRESS_INFORMATION_CLASS information)
|
45 |
| - { |
| 45 | + { |
46 | 46 | DWORD result = 0;
|
47 | 47 | THROW_IF_WIN32_BOOL_FALSE(QueryCompressorInformation(m_compressor.get(), information, &result, sizeof(result)));
|
48 |
| - return result; |
49 |
| - } |
50 |
| - |
| 48 | + return result; |
| 49 | + } |
| 50 | + |
51 | 51 | Decompressor::Decompressor(DWORD algorithm)
|
52 |
| - { |
53 |
| - THROW_IF_WIN32_BOOL_FALSE(CreateDecompressor(algorithm, nullptr, &m_decompressor)); |
54 |
| - } |
55 |
| - |
| 52 | + { |
| 53 | + THROW_IF_WIN32_BOOL_FALSE(CreateDecompressor(algorithm, nullptr, &m_decompressor)); |
| 54 | + } |
| 55 | + |
56 | 56 | std::vector<uint8_t> Decompressor::Decompress(const std::vector<uint8_t>& data)
|
57 | 57 | {
|
58 | 58 | std::vector<uint8_t> result;
|
59 | 59 |
|
60 | 60 | if (!data.empty())
|
61 |
| - { |
62 |
| - size_t decompressedBufferSize = 0; |
| 61 | + { |
| 62 | + SIZE_T decompressedBufferSize = 0; |
63 | 63 | THROW_HR_IF(E_UNEXPECTED, ::Decompress(m_decompressor.get(), data.data(), data.size(), nullptr, 0, &decompressedBufferSize));
|
64 | 64 | THROW_LAST_ERROR_IF(GetLastError() != ERROR_INSUFFICIENT_BUFFER);
|
65 | 65 |
|
66 | 66 | result.resize(decompressedBufferSize);
|
67 |
| - |
68 |
| - size_t decompressedDataSize = 0; |
| 67 | + |
| 68 | + SIZE_T decompressedDataSize = 0; |
69 | 69 | THROW_IF_WIN32_BOOL_FALSE(::Decompress(m_decompressor.get(), data.data(), data.size(), &result[0], result.size(), &decompressedDataSize));
|
70 | 70 |
|
71 | 71 | result.resize(decompressedDataSize);
|
72 | 72 | }
|
73 | 73 |
|
74 |
| - return result; |
75 |
| - } |
76 |
| - |
| 74 | + return result; |
| 75 | + } |
| 76 | + |
77 | 77 | void Decompressor::Reset()
|
78 |
| - { |
79 |
| - THROW_IF_WIN32_BOOL_FALSE(ResetDecompressor(m_decompressor.get())); |
80 |
| - } |
81 |
| - |
| 78 | + { |
| 79 | + THROW_IF_WIN32_BOOL_FALSE(ResetDecompressor(m_decompressor.get())); |
| 80 | + } |
| 81 | + |
82 | 82 | void Decompressor::SetInformation(COMPRESS_INFORMATION_CLASS information, DWORD value)
|
83 |
| - { |
84 |
| - THROW_IF_WIN32_BOOL_FALSE(SetDecompressorInformation(m_decompressor.get(), information, &value, sizeof(value))); |
85 |
| - } |
86 |
| - |
| 83 | + { |
| 84 | + THROW_IF_WIN32_BOOL_FALSE(SetDecompressorInformation(m_decompressor.get(), information, &value, sizeof(value))); |
| 85 | + } |
| 86 | + |
87 | 87 | DWORD Decompressor::GetInformation(COMPRESS_INFORMATION_CLASS information)
|
88 |
| - { |
| 88 | + { |
89 | 89 | DWORD result = 0;
|
90 | 90 | THROW_IF_WIN32_BOOL_FALSE(QueryDecompressorInformation(m_decompressor.get(), information, &result, sizeof(result)));
|
91 |
| - return result; |
92 |
| - } |
93 |
| -} |
| 91 | + return result; |
| 92 | + } |
| 93 | +} |
0 commit comments