diff options
author | qrort <qrort@yandex-team.com> | 2022-12-02 11:31:25 +0300 |
---|---|---|
committer | qrort <qrort@yandex-team.com> | 2022-12-02 11:31:25 +0300 |
commit | b1f4ffc9c8abff3ba58dc1ec9a9f92d2f0de6806 (patch) | |
tree | 2a23209faf0fea5586a6d4b9cee60d1b318d29fe /library/cpp/streams/base64 | |
parent | 559174a9144de40d6bb3997ea4073c82289b4974 (diff) | |
download | ydb-b1f4ffc9c8abff3ba58dc1ec9a9f92d2f0de6806.tar.gz |
remove kikimr/driver DEPENDS
Diffstat (limited to 'library/cpp/streams/base64')
-rw-r--r-- | library/cpp/streams/base64/base64stream.cpp | 1 | ||||
-rw-r--r-- | library/cpp/streams/base64/base64stream.h | 129 | ||||
-rw-r--r-- | library/cpp/streams/base64/static_data.cpp | 1 | ||||
-rw-r--r-- | library/cpp/streams/base64/static_data.h | 43 |
4 files changed, 0 insertions, 174 deletions
diff --git a/library/cpp/streams/base64/base64stream.cpp b/library/cpp/streams/base64/base64stream.cpp deleted file mode 100644 index b49d238829c..00000000000 --- a/library/cpp/streams/base64/base64stream.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "base64stream.h" diff --git a/library/cpp/streams/base64/base64stream.h b/library/cpp/streams/base64/base64stream.h deleted file mode 100644 index b156c468958..00000000000 --- a/library/cpp/streams/base64/base64stream.h +++ /dev/null @@ -1,129 +0,0 @@ -#pragma once - -#include <library/cpp/string_utils/base64/base64.h> - -#include <util/generic/ptr.h> -#include <util/stream/input.h> -#include <util/stream/output.h> - -class TStringDataInputStream: public IInputStream { -protected: - const char* (*GetLine)(size_t); - size_t BufferSize; - TArrayHolder<char> OutBuf; - size_t Line; - size_t LineLength; - size_t Cursor; - -private: - bool NextLine() { - Cursor = 0; - const TStringBuf str(GetLine(Line)); - if (str.empty()) { - LineLength = 0; - return false; - } - - ++Line; - - const size_t size = Base64DecodeBufSize(str.size()); - - if (BufferSize < size) { - OutBuf.Reset(new char[size]); - BufferSize = size; - } - - LineLength = Base64Decode(str, OutBuf.Get()).size(); - Y_ASSERT(LineLength <= BufferSize); - - return LineLength > 0; - } - - size_t ReadDataFromLine(char* buf, size_t len) { - size_t n = Min(len, LineLength - Cursor); - memcpy(static_cast<void*>(buf), static_cast<void*>(OutBuf.Get() + Cursor), n); - Cursor += n; - return n; - } - -protected: - size_t DoRead(void* buf, size_t len) override { - size_t readed = 0; - while (readed < len) { - readed += ReadDataFromLine(static_cast<char*>(buf) + readed, len - readed); - if (readed < len && !NextLine()) - break; - } - return readed; - } - -public: - TStringDataInputStream(const char* (*getLine)(size_t), size_t bufferSize = 0) - : GetLine(getLine) - , BufferSize(bufferSize) - , OutBuf(new char[BufferSize]) - , Line(0) - , LineLength(0) - , Cursor(0) - { - } -}; - -class TStringDataOutputStream: public IOutputStream { -public: - TStringDataOutputStream(IOutputStream* out, const int maxOutStrLen) - : mStream(out) - , MaxReadLen(Base64DecodeBufSize(maxOutStrLen)) - , BufRead(new unsigned char[MaxReadLen]) - , BufReadOffset(0) - , BufOut(new char[maxOutStrLen + 1]){}; - - ~TStringDataOutputStream() override { - try { - Finish(); - } catch (...) { - } - } - -private: - IOutputStream* mStream; - size_t MaxReadLen; - TArrayHolder<unsigned char> BufRead; - size_t BufReadOffset; - TArrayHolder<char> BufOut; - - void WriteLine() { - if (BufReadOffset > 0) { - mStream->Write(" \""); - Y_ASSERT(BufReadOffset <= MaxReadLen); - char* b = BufOut.Get(); - char* e = Base64Encode(b, BufRead.Get(), BufReadOffset); - mStream->Write(b, e - b); - mStream->Write("\",\n"); - BufReadOffset = 0; - } - } - - void DoWrite(const void* buf, size_t size) override { - size_t res = Min(MaxReadLen - BufReadOffset, size); - size_t buf_offset = 0; - while (res > 0) { - memcpy(BufRead.Get() + BufReadOffset, (const char*)buf + buf_offset, res); - BufReadOffset += res; - if (BufReadOffset < MaxReadLen) - return; - WriteLine(); - buf_offset += res; - size -= res; - res = Min(MaxReadLen - BufReadOffset, size); - } - } - - void DoFlush() override { - WriteLine(); - } - - void DoFinish() override { - DoFlush(); - } -}; diff --git a/library/cpp/streams/base64/static_data.cpp b/library/cpp/streams/base64/static_data.cpp deleted file mode 100644 index 8fe346da6ce..00000000000 --- a/library/cpp/streams/base64/static_data.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "static_data.h" diff --git a/library/cpp/streams/base64/static_data.h b/library/cpp/streams/base64/static_data.h deleted file mode 100644 index 584ac182995..00000000000 --- a/library/cpp/streams/base64/static_data.h +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include "base64stream.h" - -#include <util/memory/blob.h> -#include <util/stream/zlib.h> -#include <util/generic/ptr.h> - -class TCompressedStaticData { -public: - using TDataFunction = const char* (*)(size_t); - using TData = TBlob; - - class TDataInputStream: public IInputStream { - public: - TDataInputStream(TDataFunction function) - : Compressed(function) - , Decompressed(&Compressed) - { - } - - private: - size_t DoRead(void* buf, size_t len) override { - return Decompressed.Read(buf, len); - } - - private: - TStringDataInputStream Compressed; - TZLibDecompress Decompressed; - }; - - TCompressedStaticData(TDataFunction function) { - TDataInputStream inp(function); - Data = TBlob::FromStream(inp); - } - - const TData& GetData() const { - return Data; - } - -private: - TData Data; -}; |