forked from snowcone-ltd/libmatoya
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic compression on Windows, Unix placeholder
- Loading branch information
chrisd1100
committed
Dec 19, 2023
1 parent
61436ed
commit 57a6baf
Showing
6 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// This Source Code Form is subject to the terms of the MIT License. | ||
// If a copy of the MIT License was not distributed with this file, | ||
// You can obtain one at https://spdx.org/licenses/MIT.html. | ||
|
||
#include "matoya.h" | ||
|
||
void *MTY_Compress(const void *input, size_t inputSize, size_t *outputSize) | ||
{ | ||
*outputSize = inputSize; | ||
|
||
return MTY_Dup(input, inputSize); | ||
} | ||
|
||
void *MTY_Decompress(const void *input, size_t inputSize, size_t *outputSize) | ||
{ | ||
*outputSize = inputSize; | ||
|
||
return MTY_Dup(input, inputSize); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// This Source Code Form is subject to the terms of the MIT License. | ||
// If a copy of the MIT License was not distributed with this file, | ||
// You can obtain one at https://spdx.org/licenses/MIT.html. | ||
|
||
#include "matoya.h" | ||
|
||
#include <windows.h> | ||
#include <compressapi.h> | ||
|
||
void *MTY_Compress(const void *input, size_t inputSize, size_t *outputSize) | ||
{ | ||
COMPRESSOR_HANDLE h = NULL; | ||
|
||
if (!CreateCompressor(COMPRESS_ALGORITHM_MSZIP, NULL, &h)) | ||
return NULL; | ||
|
||
BOOL success = Compress(h, input, inputSize, NULL, 0, outputSize); | ||
if (!success && GetLastError() != ERROR_INSUFFICIENT_BUFFER) | ||
return NULL; | ||
|
||
void *output = MTY_Alloc(*outputSize, 1); | ||
|
||
if (!Compress(h, input, inputSize, output, *outputSize, outputSize)) { | ||
MTY_Free(output); | ||
output = NULL; | ||
} | ||
|
||
CloseCompressor(h); | ||
|
||
return output; | ||
} | ||
|
||
void *MTY_Decompress(const void *input, size_t inputSize, size_t *outputSize) | ||
{ | ||
DECOMPRESSOR_HANDLE h = NULL; | ||
|
||
if (!CreateDecompressor(COMPRESS_ALGORITHM_MSZIP, NULL, &h)) | ||
return NULL; | ||
|
||
BOOL success = Decompress(h, input, inputSize, NULL, 0, outputSize); | ||
if (!success && GetLastError() != ERROR_INSUFFICIENT_BUFFER) | ||
return NULL; | ||
|
||
void *output = MTY_Alloc(*outputSize, 1); | ||
|
||
if (!Decompress(h, input, inputSize, output, *outputSize, outputSize)) { | ||
MTY_Free(output); | ||
output = NULL; | ||
} | ||
|
||
CloseDecompressor(h); | ||
|
||
return output; | ||
} |