| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #ifndef CORE_INCLUDE_FXCRT_FX_STREAM_H_ | 7 #ifndef CORE_INCLUDE_FXCRT_FX_STREAM_H_ |
| 8 #define CORE_INCLUDE_FXCRT_FX_STREAM_H_ | 8 #define CORE_INCLUDE_FXCRT_FX_STREAM_H_ |
| 9 | 9 |
| 10 #include "core/include/fxcrt/fx_string.h" | 10 #include "core/include/fxcrt/fx_string.h" |
| 11 #include "core/include/fxcrt/fx_system.h" | 11 #include "core/include/fxcrt/fx_system.h" |
| 12 | 12 |
| 13 void* FX_OpenFolder(const FX_CHAR* path); | 13 void* FX_OpenFolder(const FX_CHAR* path); |
| 14 void* FX_OpenFolder(const FX_WCHAR* path); | 14 void* FX_OpenFolder(const FX_WCHAR* path); |
| 15 FX_BOOL FX_GetNextFile(void* handle, | 15 FX_BOOL FX_GetNextFile(void* handle, |
| 16 CFX_ByteString& filename, | 16 CFX_ByteString& filename, |
| 17 FX_BOOL& bFolder); | 17 FX_BOOL& bFolder); |
| 18 FX_BOOL FX_GetNextFile(void* handle, | 18 FX_BOOL FX_GetNextFile(void* handle, |
| 19 CFX_WideString& filename, | 19 CFX_WideString& filename, |
| 20 FX_BOOL& bFolder); | 20 FX_BOOL& bFolder); |
| 21 void FX_CloseFolder(void* handle); | 21 void FX_CloseFolder(void* handle); |
| 22 FX_WCHAR FX_GetFolderSeparator(); | 22 FX_WCHAR FX_GetFolderSeparator(); |
| 23 |
| 23 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 24 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 24 #define FX_FILESIZE int32_t | 25 #define FX_FILESIZE int32_t |
| 25 #else | 26 #else |
| 26 #include <fcntl.h> | 27 #include <fcntl.h> |
| 27 #include <sys/stat.h> | 28 #include <sys/stat.h> |
| 28 #include <unistd.h> | 29 #include <unistd.h> |
| 30 |
| 29 #ifndef O_BINARY | 31 #ifndef O_BINARY |
| 30 #define O_BINARY 0 | 32 #define O_BINARY 0 |
| 31 #endif | 33 #endif // O_BINARY |
| 34 |
| 32 #ifndef O_LARGEFILE | 35 #ifndef O_LARGEFILE |
| 33 #define O_LARGEFILE 0 | 36 #define O_LARGEFILE 0 |
| 34 #endif | 37 #endif // O_LARGEFILE |
| 38 |
| 35 #define FX_FILESIZE off_t | 39 #define FX_FILESIZE off_t |
| 36 #endif | 40 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 41 |
| 37 #define FX_GETBYTEOFFSET32(a) 0 | 42 #define FX_GETBYTEOFFSET32(a) 0 |
| 38 #define FX_GETBYTEOFFSET40(a) 0 | 43 #define FX_GETBYTEOFFSET40(a) 0 |
| 39 #define FX_GETBYTEOFFSET48(a) 0 | 44 #define FX_GETBYTEOFFSET48(a) 0 |
| 40 #define FX_GETBYTEOFFSET56(a) 0 | 45 #define FX_GETBYTEOFFSET56(a) 0 |
| 41 #define FX_GETBYTEOFFSET24(a) ((uint8_t)(a >> 24)) | 46 #define FX_GETBYTEOFFSET24(a) ((uint8_t)(a >> 24)) |
| 42 #define FX_GETBYTEOFFSET16(a) ((uint8_t)(a >> 16)) | 47 #define FX_GETBYTEOFFSET16(a) ((uint8_t)(a >> 16)) |
| 43 #define FX_GETBYTEOFFSET8(a) ((uint8_t)(a >> 8)) | 48 #define FX_GETBYTEOFFSET8(a) ((uint8_t)(a >> 8)) |
| 44 #define FX_GETBYTEOFFSET0(a) ((uint8_t)(a)) | 49 #define FX_GETBYTEOFFSET0(a) ((uint8_t)(a)) |
| 45 #define FX_FILEMODE_Write 0 | 50 #define FX_FILEMODE_Write 0 |
| 46 #define FX_FILEMODE_ReadOnly 1 | 51 #define FX_FILEMODE_ReadOnly 1 |
| 47 #define FX_FILEMODE_Truncate 2 | 52 #define FX_FILEMODE_Truncate 2 |
| 48 | 53 |
| 49 class IFX_StreamWrite { | 54 class IFX_StreamWrite { |
| 50 public: | 55 public: |
| 51 virtual ~IFX_StreamWrite() {} | 56 virtual ~IFX_StreamWrite() {} |
| 52 virtual void Release() = 0; | 57 virtual void Release() = 0; |
| 53 virtual FX_BOOL WriteBlock(const void* pData, size_t size) = 0; | 58 virtual FX_BOOL WriteBlock(const void* pData, size_t size) = 0; |
| 54 }; | 59 }; |
| 55 | 60 |
| 56 class IFX_FileWrite : public IFX_StreamWrite { | 61 class IFX_FileWrite : public IFX_StreamWrite { |
| 57 public: | 62 public: |
| 58 // IFX_StreamWrite: | 63 // IFX_StreamWrite: |
| 59 FX_BOOL WriteBlock(const void* pData, size_t size) override { | 64 FX_BOOL WriteBlock(const void* pData, size_t size) override; |
| 60 return WriteBlock(pData, GetSize(), size); | |
| 61 } | |
| 62 | |
| 63 virtual FX_FILESIZE GetSize() = 0; | 65 virtual FX_FILESIZE GetSize() = 0; |
| 64 virtual FX_BOOL Flush() = 0; | 66 virtual FX_BOOL Flush() = 0; |
| 65 virtual FX_BOOL WriteBlock(const void* pData, | 67 virtual FX_BOOL WriteBlock(const void* pData, |
| 66 FX_FILESIZE offset, | 68 FX_FILESIZE offset, |
| 67 size_t size) = 0; | 69 size_t size) = 0; |
| 68 }; | 70 }; |
| 69 | 71 |
| 70 class IFX_StreamRead { | 72 class IFX_StreamRead { |
| 71 public: | 73 public: |
| 72 virtual ~IFX_StreamRead() {} | 74 virtual ~IFX_StreamRead() {} |
| 73 | 75 |
| 74 virtual void Release() = 0; | 76 virtual void Release() = 0; |
| 75 virtual FX_BOOL IsEOF() = 0; | 77 virtual FX_BOOL IsEOF() = 0; |
| 76 virtual FX_FILESIZE GetPosition() = 0; | 78 virtual FX_FILESIZE GetPosition() = 0; |
| 77 virtual size_t ReadBlock(void* buffer, size_t size) = 0; | 79 virtual size_t ReadBlock(void* buffer, size_t size) = 0; |
| 78 }; | 80 }; |
| 79 | 81 |
| 80 class IFX_FileRead : IFX_StreamRead { | 82 class IFX_FileRead : IFX_StreamRead { |
| 81 public: | 83 public: |
| 82 // IFX_StreamRead: | 84 // IFX_StreamRead: |
| 83 void Release() override = 0; | 85 void Release() override = 0; |
| 84 FX_BOOL IsEOF() override { return FALSE; } | 86 FX_BOOL IsEOF() override; |
| 85 FX_FILESIZE GetPosition() override { return 0; } | 87 FX_FILESIZE GetPosition() override; |
| 86 size_t ReadBlock(void* buffer, size_t size) override { return 0; } | 88 size_t ReadBlock(void* buffer, size_t size) override; |
| 87 | 89 |
| 88 virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) = 0; | 90 virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) = 0; |
| 89 virtual FX_FILESIZE GetSize() = 0; | 91 virtual FX_FILESIZE GetSize() = 0; |
| 90 }; | 92 }; |
| 91 | 93 |
| 92 IFX_FileRead* FX_CreateFileRead(const FX_CHAR* filename); | 94 IFX_FileRead* FX_CreateFileRead(const FX_CHAR* filename); |
| 93 IFX_FileRead* FX_CreateFileRead(const FX_WCHAR* filename); | 95 IFX_FileRead* FX_CreateFileRead(const FX_WCHAR* filename); |
| 94 | 96 |
| 95 class IFX_FileStream : public IFX_FileRead, public IFX_FileWrite { | 97 class IFX_FileStream : public IFX_FileRead, public IFX_FileWrite { |
| 96 public: | 98 public: |
| 97 virtual IFX_FileStream* Retain() = 0; | 99 virtual IFX_FileStream* Retain() = 0; |
| 98 | 100 |
| 99 // IFX_FileRead: | 101 // IFX_FileRead: |
| 100 void Release() override = 0; | 102 void Release() override = 0; |
| 101 FX_BOOL IsEOF() override = 0; | 103 FX_BOOL IsEOF() override = 0; |
| 102 FX_FILESIZE GetPosition() override = 0; | 104 FX_FILESIZE GetPosition() override = 0; |
| 103 size_t ReadBlock(void* buffer, size_t size) override = 0; | 105 size_t ReadBlock(void* buffer, size_t size) override = 0; |
| 104 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override = 0; | 106 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override = 0; |
| 105 FX_FILESIZE GetSize() override = 0; | 107 FX_FILESIZE GetSize() override = 0; |
| 106 | 108 |
| 107 // IFX_FileWrite: | 109 // IFX_FileWrite: |
| 108 FX_BOOL WriteBlock(const void* buffer, | 110 FX_BOOL WriteBlock(const void* buffer, |
| 109 FX_FILESIZE offset, | 111 FX_FILESIZE offset, |
| 110 size_t size) override = 0; | 112 size_t size) override = 0; |
| 111 FX_BOOL WriteBlock(const void* buffer, size_t size) override { | 113 FX_BOOL WriteBlock(const void* buffer, size_t size) override; |
| 112 return WriteBlock(buffer, GetSize(), size); | |
| 113 } | |
| 114 FX_BOOL Flush() override = 0; | 114 FX_BOOL Flush() override = 0; |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 IFX_FileStream* FX_CreateFileStream(const FX_CHAR* filename, FX_DWORD dwModes); | 117 IFX_FileStream* FX_CreateFileStream(const FX_CHAR* filename, FX_DWORD dwModes); |
| 118 IFX_FileStream* FX_CreateFileStream(const FX_WCHAR* filename, FX_DWORD dwModes); | 118 IFX_FileStream* FX_CreateFileStream(const FX_WCHAR* filename, FX_DWORD dwModes); |
| 119 | 119 |
| 120 #ifdef PDF_ENABLE_XFA | 120 #ifdef PDF_ENABLE_XFA |
| 121 class IFX_FileAccess { | 121 class IFX_FileAccess { |
| 122 public: | 122 public: |
| 123 virtual ~IFX_FileAccess() {} | 123 virtual ~IFX_FileAccess() {} |
| 124 virtual void Release() = 0; | 124 virtual void Release() = 0; |
| 125 virtual IFX_FileAccess* Retain() = 0; | 125 virtual IFX_FileAccess* Retain() = 0; |
| 126 virtual void GetPath(CFX_WideString& wsPath) = 0; | 126 virtual void GetPath(CFX_WideString& wsPath) = 0; |
| 127 virtual IFX_FileStream* CreateFileStream(FX_DWORD dwModes) = 0; | 127 virtual IFX_FileStream* CreateFileStream(FX_DWORD dwModes) = 0; |
| 128 }; | 128 }; |
| 129 IFX_FileAccess* FX_CreateDefaultFileAccess(const CFX_WideStringC& wsPath); | 129 IFX_FileAccess* FX_CreateDefaultFileAccess(const CFX_WideStringC& wsPath); |
| 130 #endif // PDF_ENABLE_XFA | 130 #endif // PDF_ENABLE_XFA |
| 131 | 131 |
| 132 class IFX_MemoryStream : public IFX_FileStream { | 132 class IFX_MemoryStream : public IFX_FileStream { |
| 133 public: | 133 public: |
| 134 virtual FX_BOOL IsConsecutive() const = 0; | 134 virtual FX_BOOL IsConsecutive() const = 0; |
| 135 | |
| 136 virtual void EstimateSize(size_t nInitSize, size_t nGrowSize) = 0; | 135 virtual void EstimateSize(size_t nInitSize, size_t nGrowSize) = 0; |
| 137 | |
| 138 virtual uint8_t* GetBuffer() const = 0; | 136 virtual uint8_t* GetBuffer() const = 0; |
| 139 | |
| 140 virtual void AttachBuffer(uint8_t* pBuffer, | 137 virtual void AttachBuffer(uint8_t* pBuffer, |
| 141 size_t nSize, | 138 size_t nSize, |
| 142 FX_BOOL bTakeOver = FALSE) = 0; | 139 FX_BOOL bTakeOver = FALSE) = 0; |
| 143 | |
| 144 virtual void DetachBuffer() = 0; | 140 virtual void DetachBuffer() = 0; |
| 145 }; | 141 }; |
| 142 |
| 146 IFX_MemoryStream* FX_CreateMemoryStream(uint8_t* pBuffer, | 143 IFX_MemoryStream* FX_CreateMemoryStream(uint8_t* pBuffer, |
| 147 size_t nSize, | 144 size_t nSize, |
| 148 FX_BOOL bTakeOver = FALSE); | 145 FX_BOOL bTakeOver = FALSE); |
| 149 IFX_MemoryStream* FX_CreateMemoryStream(FX_BOOL bConsecutive = FALSE); | 146 IFX_MemoryStream* FX_CreateMemoryStream(FX_BOOL bConsecutive = FALSE); |
| 147 |
| 150 class IFX_BufferRead : public IFX_StreamRead { | 148 class IFX_BufferRead : public IFX_StreamRead { |
| 151 public: | 149 public: |
| 152 // IFX_StreamRead: | 150 // IFX_StreamRead: |
| 153 void Release() override = 0; | 151 void Release() override = 0; |
| 154 FX_BOOL IsEOF() override = 0; | 152 FX_BOOL IsEOF() override = 0; |
| 155 FX_FILESIZE GetPosition() override = 0; | 153 FX_FILESIZE GetPosition() override = 0; |
| 156 size_t ReadBlock(void* buffer, size_t size) override = 0; | 154 size_t ReadBlock(void* buffer, size_t size) override = 0; |
| 157 | 155 |
| 158 virtual FX_BOOL ReadNextBlock(FX_BOOL bRestart = FALSE) = 0; | 156 virtual FX_BOOL ReadNextBlock(FX_BOOL bRestart = FALSE) = 0; |
| 159 virtual const uint8_t* GetBlockBuffer() = 0; | 157 virtual const uint8_t* GetBlockBuffer() = 0; |
| 160 virtual size_t GetBlockSize() = 0; | 158 virtual size_t GetBlockSize() = 0; |
| 161 virtual FX_FILESIZE GetBlockOffset() = 0; | 159 virtual FX_FILESIZE GetBlockOffset() = 0; |
| 162 }; | 160 }; |
| 163 | 161 |
| 164 #endif // CORE_INCLUDE_FXCRT_FX_STREAM_H_ | 162 #endif // CORE_INCLUDE_FXCRT_FX_STREAM_H_ |
| OLD | NEW |