• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 #include "ext_wstream.h"
17 #include "image_log.h"
18 
19 #undef LOG_DOMAIN
20 #define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
21 
22 #undef LOG_TAG
23 #define LOG_TAG "ExtWStream"
24 
25 namespace {
26     constexpr static size_t SIZE_ZERO = 0;
27 }
28 namespace OHOS {
29 namespace ImagePlugin {
30 
ExtWStream(OutputDataStream * stream)31 ExtWStream::ExtWStream(OutputDataStream *stream) : stream_(stream)
32 {
33 }
34 
write(const void * buffer,size_t size)35 bool ExtWStream::write(const void* buffer, size_t size) __attribute__((no_sanitize("cfi")))
36 {
37     if (stream_ == nullptr) {
38         IMAGE_LOGE("ExtWStream::write stream is nullptr");
39         return false;
40     }
41     return stream_->Write(static_cast<const uint8_t*>(buffer), size);
42 }
43 
flush()44 void ExtWStream::flush()
45 {
46     if (stream_ == nullptr) {
47         IMAGE_LOGE("ExtWStream::flush stream is nullptr");
48         return;
49     }
50     stream_->Flush();
51 }
52 
bytesWritten() const53 size_t ExtWStream::bytesWritten() const
54 {
55     if (stream_ == nullptr) {
56         IMAGE_LOGE("ExtWStream::bytesWritten stream is nullptr");
57         return SIZE_ZERO;
58     }
59     size_t written = SIZE_ZERO;
60     stream_->GetCurrentSize(written);
61     return written;
62 }
63 } // namespace ImagePlugin
64 } // namespace OHOS
65