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 _FX_STREAM 8 #define _FX_STREAM 9 class IFX_Stream; 10 IFX_FileRead* FX_CreateFileRead(IFX_Stream* pBaseStream, 11 FX_BOOL bReleaseStream = FALSE); 12 IFX_FileRead* FX_CreateFileRead(IFX_BufferRead* pBufferRead, 13 FX_FILESIZE iFileSize = -1, 14 FX_BOOL bReleaseStream = TRUE); 15 IFX_FileWrite* FX_CreateFileWrite(IFX_Stream* pBaseStream, 16 FX_BOOL bReleaseStream = FALSE); 17 enum FX_STREAMACCESS { 18 FX_STREAMACCESS_Binary = 0x00, 19 FX_STREAMACCESS_Text = 0x01, 20 FX_STREAMACCESS_Read = 0x02, 21 FX_STREAMACCESS_Write = 0x04, 22 FX_STREAMACCESS_Truncate = 0x10, 23 FX_STREAMACCESS_Append = 0x20, 24 FX_STREAMACCESS_Create = 0x80, 25 }; 26 enum FX_STREAMSEEK { 27 FX_STREAMSEEK_Begin = 0, 28 FX_STREAMSEEK_Current, 29 FX_STREAMSEEK_End, 30 }; 31 class IFX_Stream { 32 public: 33 static IFX_Stream* CreateStream(IFX_FileRead* pFileRead, FX_DWORD dwAccess); 34 static IFX_Stream* CreateStream(IFX_FileWrite* pFileWrite, FX_DWORD dwAccess); 35 static IFX_Stream* CreateStream(const FX_WCHAR* pszFileName, 36 FX_DWORD dwAccess); 37 static IFX_Stream* CreateStream(uint8_t* pData, 38 int32_t length, 39 FX_DWORD dwAccess); 40 static IFX_Stream* CreateStream(IFX_BufferRead* pBufferRead, 41 FX_DWORD dwAccess, 42 int32_t iFileSize = -1, 43 FX_BOOL bReleaseBufferRead = TRUE); 44 static IFX_Stream* CreateTextStream(IFX_Stream* pBaseStream, 45 FX_BOOL bDeleteOnRelease); ~IFX_Stream()46 virtual ~IFX_Stream() {} 47 virtual void Release() = 0; 48 virtual IFX_Stream* Retain() = 0; 49 virtual FX_DWORD GetAccessModes() const = 0; 50 virtual int32_t GetLength() const = 0; 51 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) = 0; 52 virtual int32_t GetPosition() = 0; 53 virtual FX_BOOL IsEOF() const = 0; 54 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) = 0; 55 virtual int32_t ReadString(FX_WCHAR* pStr, 56 int32_t iMaxLength, 57 FX_BOOL& bEOS, 58 int32_t const* pByteSize = NULL) = 0; 59 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) = 0; 60 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) = 0; 61 virtual void Flush() = 0; 62 virtual FX_BOOL SetLength(int32_t iLength) = 0; 63 virtual int32_t GetBOM(uint8_t bom[4]) const = 0; 64 virtual FX_WORD GetCodePage() const = 0; 65 virtual FX_WORD SetCodePage(FX_WORD wCodePage) = 0; 66 virtual void Lock() = 0; 67 virtual void Unlock() = 0; 68 virtual IFX_Stream* CreateSharedStream(FX_DWORD dwAccess, 69 int32_t iOffset, 70 int32_t iLength) = 0; 71 }; 72 #endif 73