• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
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  */
15 
16 #ifndef OHOS_FILEMGMT_BACKUP_B_FILE_H
17 #define OHOS_FILEMGMT_BACKUP_B_FILE_H
18 
19 #include <memory>
20 #include <string>
21 
22 #include "unique_fd.h"
23 #include "json/json.h"
24 
25 namespace OHOS::FileManagement::Backup {
26 using namespace std;
27 class BFile {
28 public:
29     /**
30      * @brief 一次性读取文件全部内容
31      *
32      * @param fd 文件描述符
33      * @return std::unique_ptr<char[]> 文件全部内容,保证最后一个字节为'\0'
34      * @throw std::system_error IO异常
35      */
36     static std::unique_ptr<char[]> ReadFile(const UniqueFd &fd);
37 
38     /**
39      * @brief linux sendfile 二次封装
40      * @param outFd 参数是待写入内容的文件描述符
41      * @param inFd 参数是待读出内容的文件描述符
42      * @throw std::system_error IO异常
43      */
44     static void SendFile(int outFd, int inFd);
45 
46     /**
47      * @brief linux write 二次封装
48      * @param fd 参数是待写入内容的文件描述符
49      * @param str 待写入文件的字符串
50      * @throw std::system_error IO异常
51      */
52     static void Write(const UniqueFd &fd, const string &str);
53 
54     /**
55      * @brief copy file from old path to new path
56      *
57      * @param from old path
58      * @param to new path
59      * @return true copy succeess
60      * @return false some error occur
61      */
62     static bool CopyFile(const string &from, const string &to);
63 
64 private:
65 };
66 } // namespace OHOS::FileManagement::Backup
67 
68 #endif // OHOS_FILEMGMT_BACKUP_B_FILE_H