duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

compress_helpers.h (2411B)


      1 // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
      2 // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
      3 
      4 #pragma once
      5 
      6 #include "common/heap_array.h"
      7 
      8 #include <optional>
      9 #include <span>
     10 
     11 class Error;
     12 
     13 namespace CompressHelpers {
     14 enum class CompressType
     15 {
     16   Uncompressed,
     17   Zstandard,
     18   Count
     19 };
     20 
     21 using ByteBuffer = DynamicHeapArray<u8>;
     22 using OptionalByteBuffer = std::optional<ByteBuffer>;
     23 
     24 OptionalByteBuffer DecompressBuffer(CompressType type, std::span<const u8> data,
     25                                     std::optional<size_t> decompressed_size = std::nullopt, Error* error = nullptr);
     26 OptionalByteBuffer DecompressBuffer(CompressType type, OptionalByteBuffer data,
     27                                     std::optional<size_t> decompressed_size = std::nullopt, Error* error = nullptr);
     28 OptionalByteBuffer DecompressFile(std::string_view path, std::span<const u8> data,
     29                                   std::optional<size_t> decompressed_size = std::nullopt, Error* error = nullptr);
     30 OptionalByteBuffer DecompressFile(std::string_view path, OptionalByteBuffer data,
     31                                   std::optional<size_t> decompressed_size = std::nullopt, Error* error = nullptr);
     32 OptionalByteBuffer DecompressFile(const char* path, std::optional<size_t> decompressed_size = std::nullopt,
     33                                   Error* error = nullptr);
     34 OptionalByteBuffer DecompressFile(CompressType type, const char* path,
     35                                   std::optional<size_t> decompressed_size = std::nullopt, Error* error = nullptr);
     36 
     37 OptionalByteBuffer CompressToBuffer(CompressType type, const void* data, size_t data_size, int clevel = -1,
     38                                     Error* error = nullptr);
     39 OptionalByteBuffer CompressToBuffer(CompressType type, std::span<const u8> data, int clevel = -1,
     40                                     Error* error = nullptr);
     41 OptionalByteBuffer CompressToBuffer(CompressType type, OptionalByteBuffer data, int clevel = -1,
     42                                     Error* error = nullptr);
     43 bool CompressToFile(const char* path, std::span<const u8> data, int clevel = -1, bool atomic_write = true,
     44                     Error* error = nullptr);
     45 bool CompressToFile(CompressType type, const char* path, std::span<const u8> data, int clevel = -1,
     46                     bool atomic_write = true, Error* error = nullptr);
     47 } // namespace CompressHelpers