#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2021 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License // If the library is compiled as a DLL, this ensures symbols are exported #define NUCLEX_STORAGE_SOURCE 1 #include "LZipHelper.h" #if defined(NUCLEX_STORAGE_HAVE_LZIP) #include // for std::logic_error, std::runtime_error #include // for assert() namespace Nuclex { namespace Storage { namespace Compression { namespace LZip { // ------------------------------------------------------------------------------------------- // std::string LZipHelper::GetErrorMessage(enum ::LZ_Errno lzipErrorNumber) { switch(lzipErrorNumber) { case LZ_ok: { return std::string(u8"OK - there was no error."); } case LZ_bad_argument: { return std::string( u8"Bad argument - an argument passed to the LZip library had an invalid value" ); } case LZ_mem_error: { return std::string( u8"Memory error - LZip ran out of memory" ); } case LZ_sequence_error: { return std::string( u8"Sequence error - an LZip function was called when it wasn't allowed" ); } case LZ_header_error: { return std::string( u8"Header error - data is either corrupt or not LZip-compressed" ); } case LZ_unexpected_eof: { return std::string( u8"Unexpected end-of-file - LZip-compressed data is incomplete" ); } case LZ_data_error: { return std::string( u8"Data error - LZip data inconsistent. Compressed by an incompatible version?" ); } case LZ_library_error: { return std::string( u8"Library error - Internal LZip library failure" ); } default: { assert(!u8"Error number returned by LZip is documented"); std::string message(::LZ_strerror(lzipErrorNumber)); if(message.find(u8"Invalid error code") != std::string::npos) { message.assign(u8"An undocumented error number was returned"); } return message; } } } // ------------------------------------------------------------------------------------------- // void LZipHelper::ThrowExceptionForErrorNumber( const std::string &errorMessage, enum ::LZ_Errno lzipErrorNumber ) { std::string message(errorMessage); message.append(u8" - "); message.append(GetErrorMessage(lzipErrorNumber)); // TODO: Use custom exception types here, like CompressionError switch(lzipErrorNumber) { case LZ_ok: case LZ_bad_argument: case LZ_sequence_error: case LZ_library_error: { throw std::logic_error(message); } case LZ_mem_error: { throw std::bad_alloc(); //(message); } default: { throw std::runtime_error(message); } } } // ------------------------------------------------------------------------------------------- // }}}} // namespace Nuclex::Storage::Compression::LZip #endif // defined(NUCLEX_STORAGE_HAVE_LZIP)