compress_sfile.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Copyright (C) 2019 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _COMPRESS_SFILE_H_
  13. #define _COMPRESS_SFILE_H_
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. #define SFILE_READ_COMP_NONE (0x01)
  18. #define SFILE_READ_COMP_LZ4LITE (0x02)
  19. #define SFILE_WRITE_COMP_NONE (SFILE_READ_COMP_NONE << 16)
  20. #define SFILE_WRITE_COMP_LZ4LITE (SFILE_READ_COMP_LZ4LITE << 16)
  21. /**
  22. * \brief read sfile with LZ4 (lite) compression
  23. *
  24. * When \p buf is NULL, the data size will be returned.
  25. *
  26. * \param fname file path to be read
  27. * \param buf buffer for read
  28. * \param size buffer size
  29. * \return
  30. * - read data size (not file size)
  31. * - -1 on error
  32. */
  33. int lz4LiteSfileRead(const char *fname, void *buf, unsigned size);
  34. /**
  35. * \brief write sfile with LZ4 (lite) compression
  36. *
  37. * \param fname file path to be written
  38. * \param buf buffer to be written
  39. * \param size buffer size
  40. * \return
  41. * - written data size (not file size), the same as \p size
  42. * - -1 on error
  43. */
  44. int lz4LiteSfileWrite(const char *fname, const void *buf, unsigned size);
  45. /**
  46. * \brief read sfile, detect multiple compress options
  47. *
  48. * This is used for sfile compress migration. It will try to read from
  49. * various compress modes.
  50. *
  51. * \p fname is the uncompress file name. When reading from compressed
  52. * file, suffix will be added inside.
  53. *
  54. * \p option is a combination of multiple \p FILE_COMP_READ_.
  55. *
  56. * \param fname file path to be read
  57. * \param buf buffer for read
  58. * \param size buffer size
  59. * \param option compress options
  60. * \return
  61. * - read data size (not file size)
  62. * - -1 on error
  63. */
  64. int compSfileRead(const char *fname, void *buf, unsigned size, unsigned option);
  65. /**
  66. * \brief write sfile and delete obsoleted compress modes
  67. *
  68. * This is used for sfile compress migration. It will try to read from
  69. * various compress modes.
  70. *
  71. * \p option is a combination of one \p FILE_COMP_WRITE_ and multiple
  72. * \p FILE_COMP_READ_.
  73. *
  74. * \param fname file path to be written
  75. * \param buf buffer to be written
  76. * \param size buffer size
  77. * \param option compress options
  78. * \return
  79. * - written data size (not file size)
  80. * - -1 on error
  81. */
  82. int compSfileWrite(const char *fname, const void *buf, unsigned size, unsigned option);
  83. #ifdef __cplusplus
  84. }
  85. #endif
  86. #endif