-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUSSTREAM.PAS
109 lines (90 loc) · 2.46 KB
/
USSTREAM.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
{
usstream Unit
Provides read-only stream access to a part of another stream
2022 LRT
}
unit
usstream;
interface
uses
consts, utils, uexc, uclasses, types, locale, uobject, ustream, math;
type
PSubstream = ^TSubstream;
TSubstream = object (TStream)
public
constructor initWithStream(stream: PStream; fromPos, size: longint);
destructor done; virtual;
function read(buffer: pointer; count: word): word; virtual;
procedure write(buffer: pointer; count: word); virtual;
procedure seek(pos: longint); virtual;
function getPosition: longint; virtual;
function isEOF: boolean; virtual;
function getSize: longint; virtual;
function isReadOnly: boolean; virtual;
function getClassName: string; virtual;
function getClassId: word; virtual;
private
_stream: PStream;
_fromPos: longint;
_size, _position: longint;
end;
implementation
{ TSubstream public }
constructor TSubstream.initWithStream(stream: PStream; fromPos, size: longint);
begin
inherited init;
_stream := stream;
_stream^.retain;
_fromPos := fromPos;
_position := 0;
_size := size;
iassert((fromPos + size - 1) < stream^.getSize, @self, 0, S_ERR_INVALID_BOUNDS);
end;
destructor TSubstream.done;
begin
_stream^.release;
inherited done;
end;
function TSubstream.read(buffer: pointer; count: word): word;
var result: word;
begin
_stream^.seek(_fromPos + _position);
result := _stream^.read(buffer, minword(count, _size - _position));
inc(_position, result);
read := result;
end;
procedure TSubstream.write(buffer: pointer; count: word);
begin
iassert(false, @self, 0, S_ERR_UNSUPPORTED_ACTION);
end;
procedure TSubstream.seek(pos: longint);
begin
_position := pos;
end;
function TSubstream.getPosition: longint;
begin
getPosition := _position;
end;
function TSubstream.isEOF: boolean;
begin
isEOF := _position = _size;
end;
function TSubstream.getSize: longint;
begin
getSize := _size;
end;
function TSubstream.isReadOnly: boolean;
begin
isReadOnly := true;
end;
function TSubstream.getClassName: string;
begin
getClassName := 'TSubstream';
end;
function TSubstream.getClassId: word;
begin
getClassId := C_CLASS_ID_Substream;
end;
{ TSubstream private }
{ Other }
end.