IdCarrierStream.pas 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. {
  2. $Project$
  3. $Workfile$
  4. $Revision$
  5. $DateUTC$
  6. $Id$
  7. This file is part of the Indy (Internet Direct) project, and is offered
  8. under the dual-licensing agreement described on the Indy website.
  9. (http://www.indyproject.org/)
  10. Copyright:
  11. (c) 1993-2005, Chad Z. Hower and the Indy Pit Crew. All rights reserved.
  12. }
  13. {
  14. $Log$
  15. }
  16. {
  17. Rev 1.0 27-03-05 10:04:16 MterWoord
  18. Second import, first time the filenames weren't prefixed with Id
  19. Rev 1.0 27-03-05 09:08:44 MterWoord
  20. Created
  21. }
  22. unit IdCarrierStream;
  23. interface
  24. uses
  25. System.IO;
  26. type
  27. TIdCarrierStream = class(System.IO.Stream)
  28. private
  29. FInternalStream: Stream;
  30. public
  31. function get_CanRead: Boolean; override;
  32. function get_CanSeek: Boolean; override;
  33. function get_CanWrite: Boolean; override;
  34. function get_Length: Int64; override;
  35. function get_Position: Int64; override;
  36. procedure set_Position(Value: Int64); override;
  37. { Private Declarations }
  38. public
  39. constructor Create(const AInternalStream: Stream); reintroduce;
  40. destructor Destroy; override;
  41. function BeginRead(ABuffer: array of byte; AOffset: Integer; ACount: Integer; ACallback: AsyncCallback; AState: TObject) : IAsyncResult; override;
  42. function BeginWrite(ABuffer: array of byte; AOffset: Integer; ACount: Integer; ACallback: AsyncCallback; AState: TObject) : IAsyncResult; override;
  43. procedure Close; override;
  44. function EndRead(AResult: IAsyncResult) : Integer; override;
  45. procedure EndWrite(AResult: IAsyncResult); override;
  46. function Read(ABuffer: array of byte; AOffset: Integer; ACount: Integer) : Integer; override;
  47. function ReadByte : Integer; override;
  48. function Seek(AOffset: Int64; AOrigin: SeekOrigin) : Int64; override;
  49. procedure SetLength(ALength: Int64); override;
  50. procedure Write(ABuffer: array of byte; AOffset: integer; ACount: Integer); override;
  51. procedure WriteByte(AInput: byte); override;
  52. procedure Flush; override;
  53. property CanRead: Boolean read get_CanRead;
  54. property CanWrite: Boolean read get_CanWrite;
  55. property CanSeek: Boolean read get_CanSeek;
  56. property Length: Int64 read get_Length;
  57. property Position: Int64 read get_Position write set_Position;
  58. property InternalStream: Stream read FInternalStream;
  59. end;
  60. implementation
  61. function TIdCarrierStream.BeginRead(ABuffer: array of byte; AOffset,
  62. ACount: Integer; ACallback: AsyncCallback; AState: TObject): IAsyncResult;
  63. begin
  64. Result := FInternalStream.BeginRead(ABuffer, AOffset, ACount, ACallback, AState);
  65. end;
  66. function TIdCarrierStream.BeginWrite(ABuffer: array of byte; AOffset,
  67. ACount: Integer; ACallback: AsyncCallback; AState: TObject): IAsyncResult;
  68. begin
  69. Result := FInternalStream.BeginWrite(ABuffer, AOffset, ACount, ACallback, AState);
  70. end;
  71. procedure TIdCarrierStream.Close;
  72. begin
  73. // don't do anything, this is a carrierstream
  74. end;
  75. constructor TIdCarrierStream.Create(const AInternalStream: Stream);
  76. begin
  77. inherited Create;
  78. FInternalStream := AInternalStream;
  79. end;
  80. function TIdCarrierStream.get_Length: Int64;
  81. begin
  82. Result := FInternalStream.Length;
  83. end;
  84. function TIdCarrierStream.get_CanSeek: Boolean;
  85. begin
  86. Result := FInternalStream.CanSeek;
  87. end;
  88. function TIdCarrierStream.get_CanRead: Boolean;
  89. begin
  90. Result := FInternalStream.CanRead;
  91. end;
  92. function TIdCarrierStream.get_CanWrite: Boolean;
  93. begin
  94. Result := FInternalStream.CanWrite;
  95. end;
  96. function TIdCarrierStream.get_Position: Int64;
  97. begin
  98. Result := FInternalStream.Position;
  99. end;
  100. procedure TIdCarrierStream.set_Position(Value: Int64);
  101. begin
  102. FInternalStream.Position := Value;
  103. end;
  104. procedure TIdCarrierStream.Write(ABuffer: array of byte; AOffset,
  105. ACount: Integer);
  106. begin
  107. FInternalStream.Write(ABuffer, AOffset, ACount);
  108. end;
  109. function TIdCarrierStream.ReadByte: Integer;
  110. begin
  111. Result := FInternalStream.ReadByte;
  112. end;
  113. procedure TIdCarrierStream.SetLength(ALength: Int64);
  114. begin
  115. FInternalStream.SetLength(ALength);
  116. end;
  117. procedure TIdCarrierStream.WriteByte(AInput: byte);
  118. begin
  119. FInternalStream.WriteByte(AInput);
  120. end;
  121. procedure TIdCarrierStream.Flush;
  122. begin
  123. FInternalStream.Flush;
  124. end;
  125. function TIdCarrierStream.Seek(AOffset: Int64; AOrigin: SeekOrigin): Int64;
  126. begin
  127. Result := FInternalStream.Seek(AOffset, AOrigin);
  128. end;
  129. function TIdCarrierStream.EndRead(AResult: IAsyncResult): Integer;
  130. begin
  131. Result := FInternalStream.EndRead(AResult);
  132. end;
  133. function TIdCarrierStream.Read(ABuffer: array of byte; AOffset,
  134. ACount: Integer): Integer;
  135. begin
  136. Result := FInternalStream.Read(ABuffer, AOffset, ACount);
  137. end;
  138. destructor TIdCarrierStream.Destroy;
  139. begin
  140. FInternalStream := nil;
  141. inherited;
  142. end;
  143. procedure TIdCarrierStream.EndWrite(AResult: IAsyncResult);
  144. begin
  145. FInternalStream.EndWrite(AResult);
  146. end;
  147. end.