io_utils.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include <iostream>
  16. #include <memory>
  17. #include <vector>
  18. #include <string>
  19. #ifndef PADDLE_MODEL_PROTECT_IO_UTILS_H
  20. #define PADDLE_MODEL_PROTECT_IO_UTILS_H
  21. namespace ioutil {
  22. int read_file(const char* file_path, unsigned char** dataptr, size_t* sizeptr);
  23. int read_with_pos_and_length(const char* file_path, unsigned char* dataptr,
  24. size_t pos, size_t length);
  25. int read_with_pos(const char* file_path, size_t pos, unsigned char** dataptr,
  26. size_t* sizeptr);
  27. int write_file(const char* file_path, const unsigned char* dataptr,
  28. size_t sizeptr);
  29. int append_file(const char* file_path, const unsigned char* data, size_t len);
  30. size_t read_file_size(const char* file_path);
  31. int read_file_to_file(const char* src_path, const char* dst_path);
  32. int dir_exist_or_mkdir(const char* dir);
  33. /**
  34. * @return files.size()
  35. */
  36. int read_dir_files(const char* dir_path,
  37. std::vector<std::string>& files); // NOLINT
  38. } // namespace ioutil
  39. #endif // PADDLE_MODEL_PROTECT_IO_UTILS_H