• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 BLOB_JS_BLOB_H
17 #define BLOB_JS_BLOB_H
18 
19 #include <numeric>
20 #include <string>
21 #include <vector>
22 
23 #include "napi/native_api.h"
24 #include "napi/native_node_api.h"
25 #include "utils/log.h"
26 
27 namespace OHOS::buffer {
28 class Blob {
29 public:
30     Blob() = default;
31     virtual ~Blob();
32     void Init(uint8_t *blob, unsigned int length);
33     void Init(Blob *blob, int start);
34     void Init(Blob *blob, int start, int end);
35 
36     uint8_t GetByte(int index);
37     uint8_t *GetRaw();
38     unsigned int GetLength();
39     void ReadBytes(uint8_t *data, int length);
40 private:
41     uint8_t *raw_ = nullptr;
42     unsigned int length_ = 0;
43 };
44 } // namespace OHOS::buffer
45 #endif // BLOB_JS_BLOB_H