|
|
@@ -0,0 +1,69 @@ |
|
|
|
unit uutlSerialization; |
|
|
|
|
|
|
|
{$mode objfpc}{$H+} |
|
|
|
|
|
|
|
interface |
|
|
|
|
|
|
|
uses |
|
|
|
Classes, SysUtils; |
|
|
|
|
|
|
|
type |
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
IutlFileReader = interface |
|
|
|
['{3A9C3AE3-CAEE-44C9-85BE-0BCAA5C1BE7A}'] |
|
|
|
function LoadStream(const aFilename: String; const aStream: TStream): Boolean; |
|
|
|
end; |
|
|
|
|
|
|
|
IutlFileWriter = interface |
|
|
|
['{3DF84644-9FC4-4A8A-88C2-73F13E72B1ED}'] |
|
|
|
procedure SaveStream(const aFilename: String; const aStream: TStream); |
|
|
|
end; |
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
TutlSimpleFileReader = class(TInterfacedObject, IutlFileReader) |
|
|
|
public |
|
|
|
function LoadStream(const aFilename: String; const aStream: TStream): Boolean; |
|
|
|
end; |
|
|
|
|
|
|
|
TutlSimpleFileWriter = class(TInterfacedObject, IutlFileWriter) |
|
|
|
public |
|
|
|
procedure SaveStream(const aFilename: String; const aStream: TStream); |
|
|
|
end; |
|
|
|
|
|
|
|
implementation |
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
//TutlSimpleFileWriter////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
procedure TutlSimpleFileWriter.SaveStream(const aFilename: String; const aStream: TStream); |
|
|
|
var |
|
|
|
fs: TFileStream; |
|
|
|
begin |
|
|
|
fs := TFileStream.Create(aFilename, fmCreate); |
|
|
|
try |
|
|
|
fs.CopyFrom(aStream, aStream.Size - aStream.Position); |
|
|
|
finally |
|
|
|
FreeAndNil(fs); |
|
|
|
end; |
|
|
|
end; |
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
//TutlSimpleFileReader////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
function TutlSimpleFileReader.LoadStream(const aFilename: String; const aStream: TStream): Boolean; |
|
|
|
var |
|
|
|
fs: TFileStream; |
|
|
|
begin |
|
|
|
result := FileExists(aFilename); |
|
|
|
if result then begin |
|
|
|
fs := TFileStream.Create(aFilename, fmOpenRead); |
|
|
|
try |
|
|
|
aStream.CopyFrom(fs, fs.Size - fs.Position); |
|
|
|
finally |
|
|
|
FreeAndNil(fs); |
|
|
|
end; |
|
|
|
end; |
|
|
|
end; |
|
|
|
|
|
|
|
end. |
|
|
|
|