• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_MEMORYSTREAM_H_
8 #define CORE_FXCRT_CFX_MEMORYSTREAM_H_
9 
10 #include "core/fxcrt/data_vector.h"
11 #include "core/fxcrt/fx_stream.h"
12 #include "core/fxcrt/retain_ptr.h"
13 #include "core/fxcrt/span.h"
14 
15 class CFX_MemoryStream final : public IFX_SeekableStream {
16  public:
17   CONSTRUCT_VIA_MAKE_RETAIN;
18 
19   // IFX_SeekableStream
20   FX_FILESIZE GetSize() override;
21   FX_FILESIZE GetPosition() override;
22   bool IsEOF() override;
23   bool ReadBlockAtOffset(pdfium::span<uint8_t> buffer,
24                          FX_FILESIZE offset) override;
25   bool WriteBlock(pdfium::span<const uint8_t> buffer) override;
26   bool Flush() override;
27 
28   pdfium::span<const uint8_t> GetSpan() const;
29 
30  private:
31   CFX_MemoryStream();
32   ~CFX_MemoryStream() override;
33 
34   DataVector<uint8_t> m_data;
35   size_t m_nCurSize = 0;
36   size_t m_nCurPos = 0;
37 };
38 
39 #endif  // CORE_FXCRT_CFX_MEMORYSTREAM_H_
40