• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 PDFium Authors. All rights reserved.
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 "core/fxcrt/fx_string.h"
11 #include "core/fxcrt/fx_system.h"
12 #include "core/fxcrt/retain_ptr.h"
13 #include "third_party/base/compiler_specific.h"
14 
15 struct FX_FolderHandle;
16 
17 FX_FolderHandle* FX_OpenFolder(const char* path);
18 bool FX_GetNextFile(FX_FolderHandle* handle,
19                     ByteString* filename,
20                     bool* bFolder);
21 void FX_CloseFolder(FX_FolderHandle* handle);
22 
23 // Used with std::unique_ptr to automatically call FX_CloseFolder().
24 struct FxFolderHandleCloser {
operatorFxFolderHandleCloser25   inline void operator()(FX_FolderHandle* h) const { FX_CloseFolder(h); }
26 };
27 
28 #define FX_FILEMODE_ReadOnly 1
29 #define FX_FILEMODE_Truncate 2
30 
31 class IFX_WriteStream {
32  public:
33   virtual bool WriteBlock(const void* pData, size_t size) = 0;
34   virtual bool WriteString(ByteStringView str) = 0;
35 
36  protected:
37   virtual ~IFX_WriteStream() = default;
38 };
39 
40 class IFX_ArchiveStream : public IFX_WriteStream {
41  public:
42   virtual bool WriteByte(uint8_t byte) = 0;
43   virtual bool WriteDWord(uint32_t i) = 0;
44   virtual FX_FILESIZE CurrentOffset() const = 0;
45 };
46 
47 class IFX_StreamWithSize {
48  public:
49   virtual FX_FILESIZE GetSize() = 0;
50 };
51 
52 class IFX_RetainableWriteStream : virtual public Retainable,
53                                   public IFX_WriteStream {};
54 
55 class IFX_SeekableWriteStream : virtual public IFX_StreamWithSize,
56                                 public IFX_RetainableWriteStream {
57  public:
58   // IFX_WriteStream:
59   bool WriteBlock(const void* pData, size_t size) override;
60 
61   virtual bool Flush() = 0;
62   virtual bool WriteBlockAtOffset(const void* pData,
63                                   FX_FILESIZE offset,
64                                   size_t size) = 0;
65 };
66 
67 class IFX_SeekableReadStream : virtual public Retainable,
68                                virtual public IFX_StreamWithSize {
69  public:
70   static RetainPtr<IFX_SeekableReadStream> CreateFromFilename(
71       const char* filename);
72 
73   virtual bool IsEOF();
74   virtual FX_FILESIZE GetPosition();
75   virtual size_t ReadBlock(void* buffer, size_t size);
76 
77   virtual bool ReadBlockAtOffset(void* buffer,
78                                  FX_FILESIZE offset,
79                                  size_t size) WARN_UNUSED_RESULT = 0;
80 };
81 
82 class IFX_SeekableStream : public IFX_SeekableReadStream,
83                            public IFX_SeekableWriteStream {
84  public:
85   static RetainPtr<IFX_SeekableStream> CreateFromFilename(const char* filename,
86                                                           uint32_t dwModes);
87 
88   static RetainPtr<IFX_SeekableStream> CreateFromFilename(
89       const wchar_t* filename,
90       uint32_t dwModes);
91 
92   // IFX_SeekableWriteStream:
93   bool WriteBlock(const void* buffer, size_t size) override;
94   bool WriteString(ByteStringView str) override;
95 };
96 
97 #endif  // CORE_FXCRT_FX_STREAM_H_
98