xref: /aosp_15_r20/external/pdfium/core/fxcrt/cfx_seekablestreamproxy.h (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2017 The PDFium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef CORE_FXCRT_CFX_SEEKABLESTREAMPROXY_H_
8 #define CORE_FXCRT_CFX_SEEKABLESTREAMPROXY_H_
9 
10 #include <stddef.h>
11 #include <stdint.h>
12 
13 #include "core/fxcrt/fx_codepage.h"
14 #include "core/fxcrt/fx_stream.h"
15 #include "core/fxcrt/fx_types.h"
16 #include "core/fxcrt/retain_ptr.h"
17 
18 class CFX_SeekableStreamProxy final : public Retainable {
19  public:
20   CONSTRUCT_VIA_MAKE_RETAIN;
21 
22   // Unlike IFX_SeekableStreamProxy, buffers and sizes are always in terms
23   // of the number of wchar_t elementss, not bytes.
24   FX_FILESIZE GetSize();  // Estimate under worst possible expansion.
25   bool IsEOF();
26   size_t ReadBlock(wchar_t* pStr, size_t size);
27 
GetCodePage()28   FX_CodePage GetCodePage() const { return m_wCodePage; }
29   void SetCodePage(FX_CodePage wCodePage);
30 
31  private:
32   enum class From {
33     Begin = 0,
34     Current,
35   };
36 
37   explicit CFX_SeekableStreamProxy(
38       const RetainPtr<IFX_SeekableReadStream>& stream);
39   ~CFX_SeekableStreamProxy() override;
40 
41   FX_FILESIZE GetPosition();
42   void Seek(From eSeek, FX_FILESIZE iOffset);
43   size_t ReadData(uint8_t* pBuffer, size_t iBufferSize);
44 
45   FX_CodePage m_wCodePage = FX_CodePage::kDefANSI;
46   size_t m_wBOMLength = 0;
47   FX_FILESIZE m_iPosition = 0;
48   RetainPtr<IFX_SeekableReadStream> const m_pStream;
49 };
50 
51 #endif  // CORE_FXCRT_CFX_SEEKABLESTREAMPROXY_H_
52