-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathNullStream.pas
64 lines (54 loc) · 1.28 KB
/
NullStream.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
unit NullStream;
interface
uses
System.Classes,
System.SysUtils;
type
TNullStream = class(TStream)
private
FPosition: int64;
FSize: int64;
protected
procedure SetSize(NewSize: Integer); override;
public
function Seek(const Offset: int64; Origin: TSeekOrigin): int64; override;
function Read(var Buffer; Count: Longint): Longint; override;
function Write(const Buffer; Count: Longint): Longint; override;
end;
implementation
{ TNullStream }
procedure TNullStream.SetSize(NewSize: Integer);
begin
FSize := NewSize;
end;
function TNullStream.Seek(const Offset: int64; Origin: TSeekOrigin): int64;
begin
case Origin of
soBeginning:
FPosition := Offset;
soCurrent:
Inc(FPosition, Offset);
soEnd:
FPosition := FSize + Offset;
end;
Result := FPosition;
end;
function TNullStream.Read(var Buffer; Count: Integer): Longint;
begin
raise Exception.Create('Null stream cannot read');
end;
function TNullStream.Write(const Buffer; Count: Integer): Longint;
var
pos: int64;
begin
if (FPosition >= 0) and (Count >= 0) then
begin
pos := FPosition + Count;
if pos > FSize then
FSize := pos;
FPosition := pos;
exit(Count);
end;
exit(0);
end;
end.