Skip to content

Commit

Permalink
style(autofix.ci): automated formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] authored and randombk committed Dec 1, 2024
1 parent 4099734 commit f6aa348
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 131 deletions.
54 changes: 28 additions & 26 deletions src/compress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,48 @@
#include <stdexcept>
#include <cstddef>

void zlib_compress(const std::string &input, std::vector<std::byte> &output) {
uLongf compressedSize = compressBound(input.size());
output.resize(compressedSize);
void zlib_compress( const std::string &input, std::vector<std::byte> &output )
{
uLongf compressedSize = compressBound( input.size() );
output.resize( compressedSize );

int result = compress2(
reinterpret_cast<Bytef *>(output.data()),
&compressedSize,
reinterpret_cast<const Bytef *>(input.data()),
input.size(),
Z_BEST_SPEED
);

if (result != Z_OK) {
throw std::runtime_error("Zlib compression error");
reinterpret_cast<Bytef *>( output.data() ),
&compressedSize,
reinterpret_cast<const Bytef *>( input.data() ),
input.size(),
Z_BEST_SPEED
);

if( result != Z_OK ) {
throw std::runtime_error( "Zlib compression error" );
}

output.resize(compressedSize);
output.resize( compressedSize );
}

void zlib_decompress(const void *compressed_data, int compressed_size, std::string &output) {
void zlib_decompress( const void *compressed_data, int compressed_size, std::string &output )
{
// We need to guess at the decompressed size - we expect things to compress fairly well.
uLongf decompressedSize = compressed_size * 8;
output.resize(decompressedSize);
output.resize( decompressedSize );

int result;
do {
result = uncompress(
reinterpret_cast<Bytef *>(&output[0]),
&decompressedSize,
reinterpret_cast<const Bytef *>(compressed_data),
compressed_size
);
reinterpret_cast<Bytef *>( &output[0] ),
&decompressedSize,
reinterpret_cast<const Bytef *>( compressed_data ),
compressed_size
);

if (result == Z_BUF_ERROR) {
if( result == Z_BUF_ERROR ) {
decompressedSize *= 2; // Double the buffer size and retry
output.resize(decompressedSize);
} else if (result != Z_OK) {
throw std::runtime_error("Zlib decompression failed");
output.resize( decompressedSize );
} else if( result != Z_OK ) {
throw std::runtime_error( "Zlib decompression failed" );
}
} while (result == Z_BUF_ERROR);
} while( result == Z_BUF_ERROR );

output.resize(decompressedSize);
output.resize( decompressedSize );
}
4 changes: 2 additions & 2 deletions src/compress.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "fstream_utils.h"

void zlib_compress(const std::string &input, std::vector<std::byte> &output);
void zlib_decompress(const void *compressed_data, int compressed_size, std::string &output);
void zlib_compress( const std::string &input, std::vector<std::byte> &output );
void zlib_decompress( const void *compressed_data, int compressed_size, std::string &output );

#endif // CATA_SRC_COMPRESS_H
3 changes: 2 additions & 1 deletion src/main_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,8 @@ void main_menu::world_tab( const std::string &worldname )

switch( opt_val ) {
case 6: // Convert to V2 Save Format
if( query_yn( _( "Convert to V2 Save Format? A backup will be created. Conversion may take several minutes." ) ) ) {
if( query_yn(
_( "Convert to V2 Save Format? A backup will be created. Conversion may take several minutes." ) ) ) {
convert_v2();
}
break;
Expand Down
Loading

0 comments on commit f6aa348

Please sign in to comment.