FileBuffer.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //---------------------------------------------------------------------------
  2. #ifndef FileBufferH
  3. #define FileBufferH
  4. #include <classes.hpp>
  5. //---------------------------------------------------------------------------
  6. extern const wchar_t * EOLTypeNames;
  7. enum TEOLType { eolLF /* \n */, eolCRLF /* \r\n */, eolCR /* \r */ };
  8. const int cpRemoveCtrlZ = 0x01;
  9. const int cpRemoveBOM = 0x02;
  10. //---------------------------------------------------------------------------
  11. typedef void __fastcall (__closure *TTransferOutEvent)(TObject * Sender, const unsigned char * Data, size_t Len);
  12. //---------------------------------------------------------------------------
  13. class TFileBuffer
  14. {
  15. public:
  16. __fastcall TFileBuffer();
  17. virtual __fastcall ~TFileBuffer();
  18. void __fastcall Convert(char * Source, char * Dest, int Params, bool & Token);
  19. void __fastcall Convert(TEOLType Source, TEOLType Dest, int Params, bool & Token);
  20. void __fastcall Convert(char * Source, TEOLType Dest, int Params, bool & Token);
  21. void __fastcall Convert(TEOLType Source, char * Dest, int Params, bool & Token);
  22. void __fastcall Insert(int Index, const char * Buf, int Len);
  23. void __fastcall Delete(int Index, int Len);
  24. DWORD __fastcall LoadStream(TStream * Stream, const DWORD Len, bool ForceLen);
  25. DWORD __fastcall ReadStream(TStream * Stream, const DWORD Len, bool ForceLen);
  26. void __fastcall WriteToStream(TStream * Stream, const DWORD Len);
  27. void __fastcall WriteToOut(TTransferOutEvent OnTransferOut, TObject * Sender, const DWORD Len);
  28. __property TMemoryStream * Memory = { read=FMemory, write=SetMemory };
  29. __property char * Data = { read=GetData };
  30. __property int Size = { read=FSize, write=SetSize };
  31. __property int Position = { read=GetPosition, write=SetPosition };
  32. private:
  33. TMemoryStream * FMemory;
  34. int FSize;
  35. void __fastcall SetMemory(TMemoryStream * value);
  36. char * __fastcall GetData() const { return (char *)FMemory->Memory; }
  37. void __fastcall SetSize(int value);
  38. void __fastcall SetPosition(int value);
  39. int __fastcall GetPosition() const;
  40. };
  41. //---------------------------------------------------------------------------
  42. class TSafeHandleStream : public THandleStream
  43. {
  44. public:
  45. __fastcall TSafeHandleStream(int AHandle);
  46. virtual int __fastcall Read(void * Buffer, int Count);
  47. virtual int __fastcall Write(const void * Buffer, int Count);
  48. virtual int __fastcall Read(System::DynamicArray<System::Byte> Buffer, int Offset, int Count);
  49. virtual int __fastcall Write(const System::DynamicArray<System::Byte> Buffer, int Offset, int Count);
  50. };
  51. //---------------------------------------------------------------------------
  52. char * __fastcall EOLToStr(TEOLType EOLType);
  53. //---------------------------------------------------------------------------
  54. #endif