-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsgstreams.pas
49 lines (39 loc) · 1.06 KB
/
sgstreams.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
unit sgstreams;
interface
uses SysUtils, Classes, Math; {, QDialogs;}
const sbhSignature='SsB';
type
TStreamBlockHeader=packed record
Signature: packed array[0..3] of char;
Size: Cardinal;
end;
TStreamBlock=class(TMemoryStream)
public
procedure LoadFromStream(s: TStream);
procedure SaveToStream(s: TStream);
end;
implementation
procedure TStreamBlock.LoadFromStream(s: TStream);
var si: TStreamBlockHeader;
begin
Clear;
s.Read(si, sizeof(TStreamBlockHeader));
if si.Signature<>sbhSignature then
raise Exception.Create('Bad StreamBlock signature.')
else begin
if CopyFrom(s, si.Size)<>si.Size then
raise Exception.Create('Stream write error when loading Stream Block.');
Seek(0,0);
end;
end;
procedure TStreamBlock.SaveToStream(s: TStream);
var si: TStreamBlockHeader;
begin
si.Signature:=sbhSignature;
si.Size:=Size;
s.Write(si, sizeof(TStreamBlockHeader));
Seek(0,0);
if s.CopyFrom(Self, si.Size)<>si.Size then
raise Exception.Create('Stream write error when saving Stream Block.');
end;
end.