• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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_FX_STREAM_H_
8 #define CORE_FXCRT_FX_STREAM_H_
9 
10 #include <stddef.h>
11 #include <stdint.h>
12 
13 #include "core/fxcrt/bytestring.h"
14 #include "core/fxcrt/fx_types.h"
15 #include "core/fxcrt/retain_ptr.h"
16 #include "core/fxcrt/span.h"
17 
18 class IFX_WriteStream {
19  public:
20   // When `size` is 0, treat it as a no-op and return true.
21   virtual bool WriteBlock(pdfium::span<const uint8_t> data) = 0;
22 
23   bool WriteString(ByteStringView str);
24   bool WriteByte(uint8_t byte);
25   bool WriteDWord(uint32_t i);
26   bool WriteFilesize(FX_FILESIZE size);
27 
28  protected:
29   virtual ~IFX_WriteStream() = default;
30 };
31 
32 class IFX_ArchiveStream : public IFX_WriteStream {
33  public:
34   virtual FX_FILESIZE CurrentOffset() const = 0;
35 };
36 
37 class IFX_StreamWithSize {
38  public:
39   virtual FX_FILESIZE GetSize() = 0;
40 };
41 
42 class IFX_RetainableWriteStream : virtual public Retainable,
43                                   public IFX_WriteStream {};
44 
45 class IFX_SeekableWriteStream : virtual public IFX_StreamWithSize,
46                                 public IFX_RetainableWriteStream {
47  public:
48   virtual bool Flush() = 0;
49 };
50 
51 class IFX_SeekableReadStream : virtual public Retainable,
52                                virtual public IFX_StreamWithSize {
53  public:
54   static RetainPtr<IFX_SeekableReadStream> CreateFromFilename(
55       const char* filename);
56 
57   virtual bool IsEOF();
58   virtual FX_FILESIZE GetPosition();
59   [[nodiscard]] virtual bool ReadBlockAtOffset(pdfium::span<uint8_t> buffer,
60                                                FX_FILESIZE offset) = 0;
61 };
62 
63 class IFX_SeekableStream : public IFX_SeekableReadStream,
64                            public IFX_SeekableWriteStream {
65 };
66 
67 #endif  // CORE_FXCRT_FX_STREAM_H_
68