├── .gitattributes ├── Benchmark ├── LightFileStreamBenchmark.lpi └── LightFileStreamBenchmark.lpr ├── DocsCHM └── LightFileStream.chm ├── DocsHTML ├── AllClasses.html ├── AllConstants.html ├── AllFunctions.html ├── AllIdentifiers.html ├── AllTypes.html ├── AllUnits.html ├── AllVariables.html ├── ClassHierarchy.html ├── LightFileStream.TLightFileStream.html ├── LightFileStream.html ├── automated.gif ├── index.html ├── legend.html ├── pasdoc.css ├── private.gif ├── protected.gif ├── public.gif └── published.gif ├── Example ├── LightFileStreamExample.lpi └── LightFileStreamExample.lpr ├── LICENSE.md ├── LazLightFileStream.lpk ├── LazLightFileStream.pas ├── README.md ├── Source ├── GenerateCHMDocs.bat ├── GenerateCHMDocs.sh ├── GenerateHTMLDocs.bat ├── GenerateHTMLDocs.sh └── LightFileStream.pas └── update_LazLightFileStream.json /.gitattributes: -------------------------------------------------------------------------------- 1 | * linguist-vendored 2 | *.pas linguist-vendored=false 3 | *.lpr linguist-language=Pascal -------------------------------------------------------------------------------- /Benchmark/LightFileStreamBenchmark.lpi: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | <UseAppBundle Value="False"/> 16 | <ResourceType Value="res"/> 17 | </General> 18 | <BuildModes Count="2"> 19 | <Item1 Name="Release" Default="True"/> 20 | <Item2 Name="Debug"> 21 | <CompilerOptions> 22 | <Version Value="11"/> 23 | <PathDelim Value="\"/> 24 | <Target> 25 | <Filename Value="LightFileStreamBenchmarkDebug"/> 26 | </Target> 27 | <SearchPaths> 28 | <IncludeFiles Value="$(ProjOutDir)"/> 29 | <UnitOutputDirectory Value="libdebug\$(TargetCPU)-$(TargetOS)"/> 30 | </SearchPaths> 31 | <Parsing> 32 | <SyntaxOptions> 33 | <SyntaxMode Value="Delphi"/> 34 | </SyntaxOptions> 35 | </Parsing> 36 | <CodeGeneration> 37 | <Optimizations> 38 | <OptimizationLevel Value="0"/> 39 | </Optimizations> 40 | </CodeGeneration> 41 | <Linking> 42 | <Debugging> 43 | <DebugInfoType Value="dsDwarf2"/> 44 | <UseHeaptrc Value="True"/> 45 | </Debugging> 46 | </Linking> 47 | <Other> 48 | <CustomOptions Value="-b -bl -godwarfsets -godwarfmethodclassprefix -dDEBUG"/> 49 | </Other> 50 | </CompilerOptions> 51 | </Item2> 52 | </BuildModes> 53 | <PublishOptions> 54 | <Version Value="2"/> 55 | <UseFileFilters Value="True"/> 56 | </PublishOptions> 57 | <RunParams> 58 | <FormatVersion Value="2"/> 59 | <Modes Count="0"/> 60 | </RunParams> 61 | <RequiredPackages Count="2"> 62 | <Item1> 63 | <PackageName Value="LazLightFileStream"/> 64 | </Item1> 65 | <Item2> 66 | <PackageName Value="etpackage"/> 67 | </Item2> 68 | </RequiredPackages> 69 | <Units Count="1"> 70 | <Unit0> 71 | <Filename Value="LightFileStreamBenchmark.lpr"/> 72 | <IsPartOfProject Value="True"/> 73 | </Unit0> 74 | </Units> 75 | </ProjectOptions> 76 | <CompilerOptions> 77 | <Version Value="11"/> 78 | <PathDelim Value="\"/> 79 | <Target> 80 | <Filename Value="LightFileStreamBenchmark"/> 81 | </Target> 82 | <SearchPaths> 83 | <IncludeFiles Value="$(ProjOutDir)"/> 84 | <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> 85 | </SearchPaths> 86 | <Parsing> 87 | <SyntaxOptions> 88 | <SyntaxMode Value="Delphi"/> 89 | </SyntaxOptions> 90 | </Parsing> 91 | <CodeGeneration> 92 | <SmartLinkUnit Value="True"/> 93 | <Optimizations> 94 | <OptimizationLevel Value="4"/> 95 | </Optimizations> 96 | </CodeGeneration> 97 | <Linking> 98 | <Debugging> 99 | <GenerateDebugInfo Value="False"/> 100 | <UseLineInfoUnit Value="False"/> 101 | <StripSymbols Value="True"/> 102 | </Debugging> 103 | <LinkSmart Value="True"/> 104 | </Linking> 105 | <Other> 106 | <CustomOptions Value="-Ci- -Co- -CO- -Cr- -Cr- -g-"/> 107 | </Other> 108 | </CompilerOptions> 109 | <Debugging> 110 | <Exceptions Count="3"> 111 | <Item1> 112 | <Name Value="EAbort"/> 113 | </Item1> 114 | <Item2> 115 | <Name Value="ECodetoolError"/> 116 | </Item2> 117 | <Item3> 118 | <Name Value="EFOpenError"/> 119 | </Item3> 120 | </Exceptions> 121 | </Debugging> 122 | </CONFIG> 123 | -------------------------------------------------------------------------------- /Benchmark/LightFileStreamBenchmark.lpr: -------------------------------------------------------------------------------- 1 | program LightFileStreamBenchmark; 2 | 3 | {$mode Delphi}{$H+}{$J-}{$I-}{$R-} 4 | 5 | uses SysUtils, Classes, EpikTimer, LightFileStream; 6 | 7 | const 8 | QC: QWord = 1844674407370955; 9 | 10 | var 11 | QV, I, J: QWord; 12 | TimeA, TimeB, TimeC, TimeD: String; 13 | Timer: TEpikTimer; 14 | 15 | begin 16 | Timer := TEpikTimer.Create(nil); 17 | Timer.Start(); 18 | with TFileStream.Create('OutputA.bin', fmCreate) do begin 19 | for I := 0 to 2999999 do WriteQWord(QC); 20 | Free(); 21 | end; 22 | Timer.Stop(); 23 | TimeA := Timer.ElapsedStr(); 24 | Timer.Clear(); 25 | Timer.Start(); 26 | with TLightFileStream.Create('OutputB.bin') do begin 27 | for J := 0 to 2999999 do WriteQWord(QC); 28 | Close(); 29 | end; 30 | Timer.Stop(); 31 | TimeB := Timer.ElapsedStr(); 32 | Timer.Clear(); 33 | Timer.Start(); 34 | with TFileStream.Create('OutputA.bin', fmOpenRead) do begin 35 | for I := 0 to 2999999 do QV := ReadQWord(); 36 | Free(); 37 | end; 38 | Timer.Stop(); 39 | TimeC := Timer.ElapsedStr(); 40 | Timer.Clear(); 41 | Timer.Start(); 42 | with TLightFileStream.Open('OutputB.bin', fsReading) do begin 43 | for J := 0 to 2999999 do ReadQWord(QV); 44 | Close(); 45 | end; 46 | Timer.Stop(); 47 | TimeD := Timer.ElapsedStr(); 48 | Timer.Free(); 49 | WriteLn('TFileStream Write: ', TimeA); 50 | WriteLn('TLightFileStream Write: ', TimeB); 51 | WriteLn('TFileStream Read: ', TimeC); 52 | WriteLn('TLightFileStream Read: ', TimeD); 53 | DeleteFile('OutputA.bin'); 54 | DeleteFile('OutputB.bin'); 55 | end. 56 | -------------------------------------------------------------------------------- /DocsCHM/LightFileStream.chm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Akira13641/TLightFileStream/cd03620bd4fe8a344543236cbcda6629c201df2a/DocsCHM/LightFileStream.chm -------------------------------------------------------------------------------- /DocsHTML/AllClasses.html: -------------------------------------------------------------------------------- 1 | <!DOCTYPE html> 2 | <html lang="en"> 3 | <head> 4 | <title>All Classes, Interfaces, Objects and Records 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
17 |

All Classes, Interfaces, Objects and Records

18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 30 | 31 |
NameUnitDescription
TLightFileStreamLightFileStream

The sole type implemented by this unit so far. 28 | 29 |

Returns a pointer to itself from all functions to avoid unnecessary allocation or copying and to allow for a convenient "method chaining" API.

32 |
Generated by PasDoc 0.15.0. 33 | 34 |
35 | -------------------------------------------------------------------------------- /DocsHTML/AllConstants.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | All Constants 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
17 |

All Constants

18 |

19 | The units do not contain any constants.

20 |
Generated by PasDoc 0.15.0. 21 | 22 |
23 | -------------------------------------------------------------------------------- /DocsHTML/AllFunctions.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | All Functions and Procedures 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
17 |

All Functions and Procedures

18 |

19 | The units do not contain any functions or procedures.

20 |
Generated by PasDoc 0.15.0. 21 | 22 |
23 | -------------------------------------------------------------------------------- /DocsHTML/AllIdentifiers.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | All Identifiers 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
17 |

All Identifiers

18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 35 | 36 |
NameUnitDescription
PLightFileStreamLightFileStream

Type alias for a pointer to the TLightFileStream type.

TLightFileStreamLightFileStream

The sole type implemented by this unit so far. 33 | 34 |

Returns a pointer to itself from all functions to avoid unnecessary allocation or copying and to allow for a convenient "method chaining" API.

37 |
Generated by PasDoc 0.15.0. 38 | 39 |
40 | -------------------------------------------------------------------------------- /DocsHTML/AllTypes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | All Types 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
17 |

All Types

18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
NameUnitDescription
PLightFileStreamLightFileStream

Type alias for a pointer to the TLightFileStream type.

30 |
Generated by PasDoc 0.15.0. 31 | 32 |
33 | -------------------------------------------------------------------------------- /DocsHTML/AllUnits.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | All Units 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
17 |

All Units

18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
NameDescription
LightFileStream

Implements a lightweight, high-performance, non-allocating advanced-record-based wrapper around the SysUtils file handling routines as an alternative to Classes.TFileStream.

28 |
Generated by PasDoc 0.15.0. 29 | 30 |
31 | -------------------------------------------------------------------------------- /DocsHTML/AllVariables.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | All Variables 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
17 |

All Variables

18 |

19 | The units do not contain any variables.

20 |
Generated by PasDoc 0.15.0. 21 | 22 |
23 | -------------------------------------------------------------------------------- /DocsHTML/ClassHierarchy.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Class Hierarchy 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
17 |

Class Hierarchy

18 |

19 | The units do not contain any classes, interfaces or objects.

20 |
Generated by PasDoc 0.15.0. 21 | 22 |
23 | -------------------------------------------------------------------------------- /DocsHTML/LightFileStream.TLightFileStream.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | LightFileStream: Record TLightFileStream 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
17 |

Record TLightFileStream

18 | 20 |

Unit

21 | 23 |

Declaration

24 |

25 | type TLightFileStream = record

26 |

Description

27 |

28 | The sole type implemented by this unit so far. 29 | 30 |

Returns a pointer to itself from all functions to avoid unnecessary allocation or copying and to allow for a convenient "method chaining" API.

31 |

Overview

32 |

Nested Types

33 | 34 | 35 | 36 | 37 | 38 |
PublishedTFileState = (...);
39 |

Fields

40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 |
Strict PrivateFFileName: PChar;
Strict PrivateFHandle: THandle;
Strict PrivateFOpen: Boolean;
Strict PrivateFState: TFileState;
58 |

Methods

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 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 |
Publicfunction AppendAnsiChar(const Item: AnsiChar): PLightFileStream; inline;
Publicfunction AppendAnsiString(const Item: AnsiString): PLightFileStream; inline;
Publicfunction AppendByte(const Item: Byte): PLightFileStream; inline;
Publicfunction AppendCurrency(const Item: Currency): PLightFileStream; inline;
Publicfunction AppendDateTime(const Item: TDateTime): PLightFileStream; inline;
Publicfunction AppendDouble(const Item: Double): PLightFileStream; inline;
Publicfunction AppendExtended(const Item: Extended): PLightFileStream; inline;
Publicfunction AppendInt64(const Item: Int64): PLightFileStream; inline;
Publicfunction AppendLongInt(const Item: LongInt): PLightFileStream; inline;
Publicfunction AppendLongWord(const Item: LongWord): PLightFileStream; inline;
Publicfunction AppendPointerBuffer(const Buffer: Pointer; const NumBytesToWrite: SizeInt): PLightFileStream; inline;
Publicfunction AppendQWord(const Item: QWord): PLightFileStream; inline;
Publicfunction AppendShortInt(const Item: ShortInt): PLightFileStream; inline;
Publicfunction AppendShortString(const Item: ShortString): PLightFileStream; inline;
Publicfunction AppendSingle(const Item: Single): PLightFileStream; inline;
Publicfunction AppendSmallInt(const Item: SmallInt): PLightFileStream; inline;
Publicfunction AppendType<T>(constref Item: T): PLightFileStream; inline;
Publicfunction AppendTypedBuffer<T>(constref Buffer: T; const ItemCount: SizeInt): PLightFileStream; inline;
Publicfunction AppendUnicodeChar(const Item: UnicodeChar): PLightFileStream; inline;
Publicfunction AppendUnicodeString(const Item: UnicodeString): PLightFileStream; inline;
Publicfunction AppendWideChar(const Item: WideChar): PLightFileStream; inline;
Publicfunction AppendWideString(const Item: WideString): PLightFileStream; inline;
Publicfunction AppendWord(const Item: Word): PLightFileStream; inline;
Publicfunction ChangeFileStateTo(const State: TFileState): PLightFileStream; inline;
Publicclass function Create(const FileName: PChar): TLightFileStream; static; inline;
Publicfunction FillWith<T>(constref Value: T; const NumInstances: SizeUInt): PLightFileStream; inline;
Publicfunction GetPosition(out ThePosition: SizeInt): PLightFileStream; inline;
Publicfunction GetSize(out TheSize: SizeInt): PLightFileStream; inline;
Publicfunction LogPosition: PLightFileStream; inline;
Publicfunction LogSize: PLightFileStream; inline;
Publicclass function Open(const FileName: PChar; const InitialState: TFileState): TLightFileStream; static; inline;
Publicfunction PutPosition: SizeInt; inline;
Publicfunction PutSize: SizeInt; inline;
Publicfunction ReadAnsiChar(var Item: AnsiChar): PLightFileStream; inline;
Publicfunction ReadAnsiString(var Item: AnsiString; const NumChars: SizeInt): PLightFileStream; inline;
Publicfunction ReadByte(var Item: Byte): PLightFileStream; inline;
Publicfunction ReadCurrency(var Item: Currency): PLightFileStream; inline;
Publicfunction ReadDateTime(var Item: TDateTime): PLightFileStream; inline;
Publicfunction ReadDouble(var Item: Double): PLightFileStream; inline;
Publicfunction ReadExtended(var Item: Extended): PLightFileStream; inline;
Publicfunction ReadInt64(var Item: Int64): PLightFileStream; inline;
Publicfunction ReadLongInt(var Item: LongInt): PLightFileStream; inline;
Publicfunction ReadLongWord(var Item: LongWord): PLightFileStream; inline;
Publicfunction ReadPointerBuffer(const Buffer: Pointer; const NumBytesToRead: SizeInt): PLightFileStream; inline;
Publicfunction ReadQWord(var Item: QWord): PLightFileStream; inline;
Publicfunction ReadShortInt(var Item: ShortInt): PLightFileStream; inline;
Publicfunction ReadShortString(var Item: ShortString; const NumChars: SizeInt): PLightFileStream; inline;
Publicfunction ReadSingle(var Item: Single): PLightFileStream; inline;
Publicfunction ReadSmallInt(var Item: SmallInt): PLightFileStream; inline;
Publicfunction ReadType<T>(var Item: T): PLightFileStream; inline;
Publicfunction ReadTypedBuffer<T>(var Buffer: T; const ItemCount: SizeInt): PLightFileStream; inline;
Publicfunction ReadUnicodeChar(var Item: UnicodeChar): PLightFileStream; inline;
Publicfunction ReadUnicodeString(var Item: UnicodeString; const NumChars: SizeInt): PLightFileStream; inline;
Publicfunction ReadWideChar(var Item: WideChar): PLightFileStream; inline;
Publicfunction ReadWideString(var Item: WideString; const NumChars: SizeInt): PLightFileStream; inline;
Publicfunction ReadWord(var Item: Word): PLightFileStream; inline;
Publicfunction SeekFromBeginning(const ToPosition: SizeInt): PLightFileStream; inline;
Publicfunction SeekFromCurrent(const ToPosition: SizeInt): PLightFileStream; inline;
Publicfunction SeekFromEnd(const ToPosition: SizeInt): PLightFileStream; inline;
Publicfunction Truncate: PLightFileStream; inline;
Publicfunction WriteAnsiChar(const Item: AnsiChar): PLightFileStream; inline;
Publicfunction WriteAnsiString(const Item: AnsiString): PLightFileStream; inline;
Publicfunction WriteByte(const Item: Byte): PLightFileStream; inline;
Publicfunction WriteCurrency(const Item: Currency): PLightFileStream; inline;
Publicfunction WriteDateTime(const Item: TDateTime): PLightFileStream; inline;
Publicfunction WriteDouble(const Item: Double): PLightFileStream; inline;
Publicfunction WriteExtended(const Item: Extended): PLightFileStream; inline;
Publicfunction WriteInt64(const Item: Int64): PLightFileStream; inline;
Publicfunction WriteLongInt(const Item: LongInt): PLightFileStream; inline;
Publicfunction WriteLongWord(const Item: LongWord): PLightFileStream; inline;
Publicfunction WritePointerBuffer(const Buffer: Pointer; const NumBytesToWrite: SizeInt): PLightFileStream; inline;
Publicfunction WriteQWord(const Item: QWord): PLightFileStream; inline;
Publicfunction WriteShortInt(const Item: ShortInt): PLightFileStream; inline;
Publicfunction WriteShortString(const Item: ShortString): PLightFileStream; inline;
Publicfunction WriteSingle(const Item: Single): PLightFileStream; inline;
Publicfunction WriteSmallInt(const Item: SmallInt): PLightFileStream; inline;
Publicfunction WriteType<T>(constref Item: T): PLightFileStream; inline;
Publicfunction WriteTypedBuffer<T>(constref Buffer: T; const ItemCount: SizeInt): PLightFileStream; inline;
Publicfunction WriteUnicodeChar(const Item: UnicodeChar): PLightFileStream; inline;
Publicfunction WriteUnicodeString(const Item: UnicodeString): PLightFileStream; inline;
Publicfunction WriteWideChar(const Item: WideChar): PLightFileStream; inline;
Publicfunction WriteWideString(const Item: WideString): PLightFileStream; inline;
Publicfunction WriteWord(const Item: Word): PLightFileStream; inline;
Publicprocedure Close; inline;
397 |

Properties

398 | 399 | 400 | 401 | 402 | 403 |
Publicproperty IsOpen: Boolean read FOpen;
404 |

Description

405 |

Nested Types

406 | 407 | 408 | 409 | 410 | 411 | 424 |
PublishedTFileState = (...);
412 |

413 | Determines whether read or write operations are actively accepted. 414 | 415 |

All functions return immediately without doing anything if the current state is "wrong" relative to them, unless {$define LIGHTFILESTREAM_NOCHECKS} is set, which improves performance but is somewhat less "safe."

416 |
Values
417 |
    418 |
  • 419 | fsReading
  • 420 |
  • 421 | fsWriting
  • 422 |
423 |
425 |

Fields

426 | 427 | 428 | 429 | 430 | 431 | 435 |
Strict PrivateFFileName: PChar;
432 |

433 | The name of the underlying file on disk.

434 |
436 | 437 | 438 | 439 | 440 | 441 | 445 |
Strict PrivateFHandle: THandle;
442 |

443 | The handle of the underlying file on disk.

444 |
446 | 447 | 448 | 449 | 450 | 451 | 457 |
Strict PrivateFOpen: Boolean;
452 |

453 | Indicates whether the file is open and can be accessed at all. 454 | 455 |

All functions return immediately without doing anything in the event that this is false, unless {$define LIGHTFILESTREAM_NOCHECKS} is set, which improves performance but is somewhat less "safe."

456 |
458 | 459 | 460 | 461 | 462 | 463 | 467 |
Strict PrivateFState: TFileState;
464 |

465 | A private instance of TFileState, used as described above.

466 |
468 |

Methods

469 | 470 | 471 | 472 | 473 | 474 | 478 |
Publicfunction AppendAnsiChar(const Item: AnsiChar): PLightFileStream; inline;
475 |

476 | Writes a single instance of AnsiChar from Item to the underlying file at the last position, behind any existing data.

477 |
479 | 480 | 481 | 482 | 483 | 484 | 488 |
Publicfunction AppendAnsiString(const Item: AnsiString): PLightFileStream; inline;
485 |

486 | Writes a single instance of AnsiString from Item to the underlying file at the last position, behind any existing data.

487 |
489 | 490 | 491 | 492 | 493 | 494 | 498 |
Publicfunction AppendByte(const Item: Byte): PLightFileStream; inline;
495 |

496 | Writes a single instance of Byte from Item to the underlying file at the last position, behind any existing data.

497 |
499 | 500 | 501 | 502 | 503 | 504 | 508 |
Publicfunction AppendCurrency(const Item: Currency): PLightFileStream; inline;
505 |

506 | Writes a single instance of Currency from Item to the underlying file at the last position, behind any existing data.

507 |
509 | 510 | 511 | 512 | 513 | 514 | 518 |
Publicfunction AppendDateTime(const Item: TDateTime): PLightFileStream; inline;
515 |

516 | Writes a single instance of TDateTime from Item to the underlying file at the last position, behind any existing data.

517 |
519 | 520 | 521 | 522 | 523 | 524 | 528 |
Publicfunction AppendDouble(const Item: Double): PLightFileStream; inline;
525 |

526 | Writes a single instance of Double from Item to the underlying file at the last position, behind any existing data.

527 |
529 | 530 | 531 | 532 | 533 | 534 | 538 |
Publicfunction AppendExtended(const Item: Extended): PLightFileStream; inline;
535 |

536 | Writes a single instance of Extended from Item to the underlying file at the last position, behind any existing data.

537 |
539 | 540 | 541 | 542 | 543 | 544 | 548 |
Publicfunction AppendInt64(const Item: Int64): PLightFileStream; inline;
545 |

546 | Writes a single instance of Int64 from Item to the underlying file at the last position, behind any existing data.

547 |
549 | 550 | 551 | 552 | 553 | 554 | 558 |
Publicfunction AppendLongInt(const Item: LongInt): PLightFileStream; inline;
555 |

556 | Writes a single instance of LongInt from Item to the underlying file at the last position, behind any existing data.

557 |
559 | 560 | 561 | 562 | 563 | 564 | 568 |
Publicfunction AppendLongWord(const Item: LongWord): PLightFileStream; inline;
565 |

566 | Writes a single instance of LongWord from Item to the underlying file at the last position, behind any existing data.

567 |
569 | 570 | 571 | 572 | 573 | 574 | 578 |
Publicfunction AppendPointerBuffer(const Buffer: Pointer; const NumBytesToWrite: SizeInt): PLightFileStream; inline;
575 |

576 | Assumes Buffer is pointing to something like the first value of an array of any type. Writes NumBytesToWrite bytes from it to the underlying file at the last position, behind any existing data.

577 |
579 | 580 | 581 | 582 | 583 | 584 | 588 |
Publicfunction AppendQWord(const Item: QWord): PLightFileStream; inline;
585 |

586 | Writes a single instance of QWord from Item to the underlying file at the last position, behind any existing data.

587 |
589 | 590 | 591 | 592 | 593 | 594 | 598 |
Publicfunction AppendShortInt(const Item: ShortInt): PLightFileStream; inline;
595 |

596 | Writes a single instance of ShortInt from Item to the underlying file at the last position, behind any existing data.

597 |
599 | 600 | 601 | 602 | 603 | 604 | 608 |
Publicfunction AppendShortString(const Item: ShortString): PLightFileStream; inline;
605 |

606 | Writes a single instance of ShortString from Item to the underlying file at the last position, behind any existing data.

607 |
609 | 610 | 611 | 612 | 613 | 614 | 618 |
Publicfunction AppendSingle(const Item: Single): PLightFileStream; inline;
615 |

616 | Writes a single instance of Single from Item to the underlying file at the last position, behind any existing data.

617 |
619 | 620 | 621 | 622 | 623 | 624 | 628 |
Publicfunction AppendSmallInt(const Item: SmallInt): PLightFileStream; inline;
625 |

626 | Writes a single instance of SmallInt from Item to the underlying file at the last position, behind any existing data.

627 |
629 | 630 | 631 | 632 | 633 | 634 | 638 |
Publicfunction AppendType<T>(constref Item: T): PLightFileStream; inline;
635 |

636 | Writes a single instance of T from Item to the underlying file at the last position, behind any existing data.

637 |
639 | 640 | 641 | 642 | 643 | 644 | 648 |
Publicfunction AppendTypedBuffer<T>(constref Buffer: T; const ItemCount: SizeInt): PLightFileStream; inline;
645 |

646 | Assumes Buffer is something like the first value of an array of T. Writes ItemCount items from it to the underlying file at the last position, behind any existing data.

647 |
649 | 650 | 651 | 652 | 653 | 654 | 658 |
Publicfunction AppendUnicodeChar(const Item: UnicodeChar): PLightFileStream; inline;
655 |

656 | Writes a single instance of UnicodeChar from Item to the underlying file at the last position, behind any existing data.

657 |
659 | 660 | 661 | 662 | 663 | 664 | 668 |
Publicfunction AppendUnicodeString(const Item: UnicodeString): PLightFileStream; inline;
665 |

666 | Writes a single instance of UnicodeString from Item to the underlying file at the last position, behind any existing data.

667 |
669 | 670 | 671 | 672 | 673 | 674 | 678 |
Publicfunction AppendWideChar(const Item: WideChar): PLightFileStream; inline;
675 |

676 | Writes a single instance of WideChar from Item to the underlying file at the last position, behind any existing data.

677 |
679 | 680 | 681 | 682 | 683 | 684 | 688 |
Publicfunction AppendWideString(const Item: WideString): PLightFileStream; inline;
685 |

686 | Writes a single instance of WideString from Item to the underlying file at the last position, behind any existing data.

687 |
689 | 690 | 691 | 692 | 693 | 694 | 698 |
Publicfunction AppendWord(const Item: Word): PLightFileStream; inline;
695 |

696 | Writes a single instance of Word from Item to the underlying file at the last position, behind any existing data.

697 |
699 | 700 | 701 | 702 | 703 | 704 | 708 |
Publicfunction ChangeFileStateTo(const State: TFileState): PLightFileStream; inline;
705 |

706 | Calls FileClose() on FHandle, then calls FileOpen() with either fmOpenRead or fmOpenWrite internally based on the provided State value. FState is then set to State.

707 |
709 | 710 | 711 | 712 | 713 | 714 | 718 |
Publicclass function Create(const FileName: PChar): TLightFileStream; static; inline;
715 |

716 | Assumes FileName does not yet exist on disk. Calls FileCreate() internally. FState is then set to fsWriting, and FOpen is set to True.

717 |
719 | 720 | 721 | 722 | 723 | 724 | 728 |
Publicfunction FillWith<T>(constref Value: T; const NumInstances: SizeUInt): PLightFileStream; inline;
725 |

726 | Writes NumInstances instances of Value to the underlying file at the current position.

727 |
729 | 730 | 731 | 732 | 733 | 734 | 738 |
Publicfunction GetPosition(out ThePosition: SizeInt): PLightFileStream; inline;
735 |

736 | Returns the current position of the underlying file in ThePosition, and a self-pointer from the function itself.

737 |
739 | 740 | 741 | 742 | 743 | 744 | 748 |
Publicfunction GetSize(out TheSize: SizeInt): PLightFileStream; inline;
745 |

746 | Returns the size in bytes of the underlying file in TheSize, and a self-pointer from the function itself.

747 |
749 | 750 | 751 | 752 | 753 | 754 | 758 |
Publicfunction LogPosition: PLightFileStream; inline;
755 |

756 | Calls GetPosition() internally and displays the value with WriteLn().

757 |
759 | 760 | 761 | 762 | 763 | 764 | 768 |
Publicfunction LogSize: PLightFileStream; inline;
765 |

766 | Calls GetSize() internally and displays the value with WriteLn().

767 |
769 | 770 | 771 | 772 | 773 | 774 | 780 |
Publicclass function Open(const FileName: PChar; const InitialState: TFileState): TLightFileStream; static; inline;
775 |

776 | Assumes FileName already exists on disk. Calls FileOpen() with either fmOpenRead or fmOpenWrite internally based on the provided InitialState value. 777 | 778 |

FState is then set to InitialState, and FOpen is set to True.

779 |
781 | 782 | 783 | 784 | 785 | 786 | 790 |
Publicfunction PutPosition: SizeInt; inline;
787 |

788 | Returns the current position of the underlying file.

789 |
791 | 792 | 793 | 794 | 795 | 796 | 800 |
Publicfunction PutSize: SizeInt; inline;
797 |

798 | Returns the size in bytes of the underlying file.

799 |
801 | 802 | 803 | 804 | 805 | 806 | 810 |
Publicfunction ReadAnsiChar(var Item: AnsiChar): PLightFileStream; inline;
807 |

808 | Reads a single instance of AnsiChar into Item from the underlying file at the current position.

809 |
811 | 812 | 813 | 814 | 815 | 816 | 820 |
Publicfunction ReadAnsiString(var Item: AnsiString; const NumChars: SizeInt): PLightFileStream; inline;
817 |

818 | Reads NumChars worth of AnsiChars into Item from the underlying file at the current position.

819 |
821 | 822 | 823 | 824 | 825 | 826 | 830 |
Publicfunction ReadByte(var Item: Byte): PLightFileStream; inline;
827 |

828 | Reads a single instance of Byte into Item from the underlying file at the current position.

829 |
831 | 832 | 833 | 834 | 835 | 836 | 840 |
Publicfunction ReadCurrency(var Item: Currency): PLightFileStream; inline;
837 |

838 | Reads a single instance of Currency into Item from the underlying file at the current position.

839 |
841 | 842 | 843 | 844 | 845 | 846 | 850 |
Publicfunction ReadDateTime(var Item: TDateTime): PLightFileStream; inline;
847 |

848 | Reads a single instance of TDateTime into Item from the underlying file at the current position.

849 |
851 | 852 | 853 | 854 | 855 | 856 | 860 |
Publicfunction ReadDouble(var Item: Double): PLightFileStream; inline;
857 |

858 | Reads a single instance of Double into Item from the underlying file at the current position.

859 |
861 | 862 | 863 | 864 | 865 | 866 | 870 |
Publicfunction ReadExtended(var Item: Extended): PLightFileStream; inline;
867 |

868 | Reads a single instance of Extended into Item from the underlying file at the current position.

869 |
871 | 872 | 873 | 874 | 875 | 876 | 880 |
Publicfunction ReadInt64(var Item: Int64): PLightFileStream; inline;
877 |

878 | Reads a single instance of Int64 into Item from the underlying file at the current position.

879 |
881 | 882 | 883 | 884 | 885 | 886 | 890 |
Publicfunction ReadLongInt(var Item: LongInt): PLightFileStream; inline;
887 |

888 | Reads a single instance of LongInt into Item from the underlying file at the current position.

889 |
891 | 892 | 893 | 894 | 895 | 896 | 900 |
Publicfunction ReadLongWord(var Item: LongWord): PLightFileStream; inline;
897 |

898 | Reads a single instance of LongWord into Item from the underlying file at the current position.

899 |
901 | 902 | 903 | 904 | 905 | 906 | 910 |
Publicfunction ReadPointerBuffer(const Buffer: Pointer; const NumBytesToRead: SizeInt): PLightFileStream; inline;
907 |

908 | Assumes Buffer is pointing to something like the first value of an array of any type. Reads NumBytesToRead bytes into it from the underlying file at the current position.

909 |
911 | 912 | 913 | 914 | 915 | 916 | 920 |
Publicfunction ReadQWord(var Item: QWord): PLightFileStream; inline;
917 |

918 | Reads a single instance of QWord into Item from the underlying file at the current position.

919 |
921 | 922 | 923 | 924 | 925 | 926 | 930 |
Publicfunction ReadShortInt(var Item: ShortInt): PLightFileStream; inline;
927 |

928 | Reads a single instance of ShortInt into Item from the underlying file at the current position.

929 |
931 | 932 | 933 | 934 | 935 | 936 | 940 |
Publicfunction ReadShortString(var Item: ShortString; const NumChars: SizeInt): PLightFileStream; inline;
937 |

938 | Reads NumChars worth of AnsiChars into Item from the underlying file at the current position.

939 |
941 | 942 | 943 | 944 | 945 | 946 | 950 |
Publicfunction ReadSingle(var Item: Single): PLightFileStream; inline;
947 |

948 | Reads a single instance of Single into Item from the underlying file at the current position.

949 |
951 | 952 | 953 | 954 | 955 | 956 | 960 |
Publicfunction ReadSmallInt(var Item: SmallInt): PLightFileStream; inline;
957 |

958 | Reads a single instance of SmallInt into Item from the underlying file at the current position.

959 |
961 | 962 | 963 | 964 | 965 | 966 | 970 |
Publicfunction ReadType<T>(var Item: T): PLightFileStream; inline;
967 |

968 | Reads a single instance of T into Item from the underlying file at the current position.

969 |
971 | 972 | 973 | 974 | 975 | 976 | 980 |
Publicfunction ReadTypedBuffer<T>(var Buffer: T; const ItemCount: SizeInt): PLightFileStream; inline;
977 |

978 | Assumes Buffer is something like the first value of an array of T. Reads ItemCount items into it from the underlying file at the current position.

979 |
981 | 982 | 983 | 984 | 985 | 986 | 990 |
Publicfunction ReadUnicodeChar(var Item: UnicodeChar): PLightFileStream; inline;
987 |

988 | Reads a single instance of UnicodeChar into Item from the underlying file at the current position.

989 |
991 | 992 | 993 | 994 | 995 | 996 | 1000 |
Publicfunction ReadUnicodeString(var Item: UnicodeString; const NumChars: SizeInt): PLightFileStream; inline;
997 |

998 | Reads NumChars worth of UnicodeChars into Item from the underlying file at the current position.

999 |
1001 | 1002 | 1003 | 1004 | 1005 | 1006 | 1010 |
Publicfunction ReadWideChar(var Item: WideChar): PLightFileStream; inline;
1007 |

1008 | Reads a single instance of WideChar into Item from the underlying file at the current position.

1009 |
1011 | 1012 | 1013 | 1014 | 1015 | 1016 | 1020 |
Publicfunction ReadWideString(var Item: WideString; const NumChars: SizeInt): PLightFileStream; inline;
1017 |

1018 | Reads NumChars worth of WideChars into Item from the underlying file at the current position.

1019 |
1021 | 1022 | 1023 | 1024 | 1025 | 1026 | 1030 |
Publicfunction ReadWord(var Item: Word): PLightFileStream; inline;
1027 |

1028 | Reads a single instance of Word into Item from the underlying file at the current position.

1029 |
1031 | 1032 | 1033 | 1034 | 1035 | 1036 | 1040 |
Publicfunction SeekFromBeginning(const ToPosition: SizeInt): PLightFileStream; inline;
1037 |

1038 | Sets the current position of the underlying file to ToPosition, relative to 0.

1039 |
1041 | 1042 | 1043 | 1044 | 1045 | 1046 | 1050 |
Publicfunction SeekFromCurrent(const ToPosition: SizeInt): PLightFileStream; inline;
1047 |

1048 | Sets the current position of the underlying file to ToPosition, relative to itself.

1049 |
1051 | 1052 | 1053 | 1054 | 1055 | 1056 | 1060 |
Publicfunction SeekFromEnd(const ToPosition: SizeInt): PLightFileStream; inline;
1057 |

1058 | Sets the current position of the underlying file to ToPosition, relative to the end of the file.

1059 |
1061 | 1062 | 1063 | 1064 | 1065 | 1066 | 1070 |
Publicfunction Truncate: PLightFileStream; inline;
1067 |

1068 | Truncates the underlying file at the current position.

1069 |
1071 | 1072 | 1073 | 1074 | 1075 | 1076 | 1080 |
Publicfunction WriteAnsiChar(const Item: AnsiChar): PLightFileStream; inline;
1077 |

1078 | Writes a single instance of AnsiChar from Item to the underlying file at the current position, possibly overwriting existing data.

1079 |
1081 | 1082 | 1083 | 1084 | 1085 | 1086 | 1090 |
Publicfunction WriteAnsiString(const Item: AnsiString): PLightFileStream; inline;
1087 |

1088 | Writes a single instance of AnsiString from Item to the underlying file at the current position, possibly overwriting existing data.

1089 |
1091 | 1092 | 1093 | 1094 | 1095 | 1096 | 1100 |
Publicfunction WriteByte(const Item: Byte): PLightFileStream; inline;
1097 |

1098 | Writes a single instance of Byte from Item to the underlying file at the current position, possibly overwriting existing data.

1099 |
1101 | 1102 | 1103 | 1104 | 1105 | 1106 | 1110 |
Publicfunction WriteCurrency(const Item: Currency): PLightFileStream; inline;
1107 |

1108 | Writes a single instance of Currency from Item to the underlying file at the current position, possibly overwriting existing data.

1109 |
1111 | 1112 | 1113 | 1114 | 1115 | 1116 | 1120 |
Publicfunction WriteDateTime(const Item: TDateTime): PLightFileStream; inline;
1117 |

1118 | Writes a single instance of TDateTime from Item to the underlying file at the current position, possibly overwriting existing data.

1119 |
1121 | 1122 | 1123 | 1124 | 1125 | 1126 | 1130 |
Publicfunction WriteDouble(const Item: Double): PLightFileStream; inline;
1127 |

1128 | Writes a single instance of Double from Item to the underlying file at the current position, possibly overwriting existing data.

1129 |
1131 | 1132 | 1133 | 1134 | 1135 | 1136 | 1140 |
Publicfunction WriteExtended(const Item: Extended): PLightFileStream; inline;
1137 |

1138 | Writes a single instance of Extended from Item to the underlying file at the current position, possibly overwriting existing data.

1139 |
1141 | 1142 | 1143 | 1144 | 1145 | 1146 | 1150 |
Publicfunction WriteInt64(const Item: Int64): PLightFileStream; inline;
1147 |

1148 | Writes a single instance of Int64 from Item to the underlying file at the current position, possibly overwriting existing data.

1149 |
1151 | 1152 | 1153 | 1154 | 1155 | 1156 | 1160 |
Publicfunction WriteLongInt(const Item: LongInt): PLightFileStream; inline;
1157 |

1158 | Writes a single instance of LongInt from Item to the underlying file at the current position, possibly overwriting existing data.

1159 |
1161 | 1162 | 1163 | 1164 | 1165 | 1166 | 1170 |
Publicfunction WriteLongWord(const Item: LongWord): PLightFileStream; inline;
1167 |

1168 | Writes a single instance of LongWord from Item to the underlying file at the current position, possibly overwriting existing data.

1169 |
1171 | 1172 | 1173 | 1174 | 1175 | 1176 | 1182 |
Publicfunction WritePointerBuffer(const Buffer: Pointer; const NumBytesToWrite: SizeInt): PLightFileStream; inline;
1177 |

1178 | Assumes Buffer is pointing to something like the first value of an array of any type. 1179 | 1180 |

Writes NumBytesToWrite bytes from it to the underlying file at the current position, possibly overwriting existing data.

1181 |
1183 | 1184 | 1185 | 1186 | 1187 | 1188 | 1192 |
Publicfunction WriteQWord(const Item: QWord): PLightFileStream; inline;
1189 |

1190 | Writes a single instance of QWord from Item to the underlying file at the current position, possibly overwriting existing data.

1191 |
1193 | 1194 | 1195 | 1196 | 1197 | 1198 | 1202 |
Publicfunction WriteShortInt(const Item: ShortInt): PLightFileStream; inline;
1199 |

1200 | Writes a single instance of ShortInt from Item to the underlying file at the current position, possibly overwriting existing data.

1201 |
1203 | 1204 | 1205 | 1206 | 1207 | 1208 | 1212 |
Publicfunction WriteShortString(const Item: ShortString): PLightFileStream; inline;
1209 |

1210 | Writes a single instance of ShortString from Item to the underlying file at the current position, possibly overwriting existing data.

1211 |
1213 | 1214 | 1215 | 1216 | 1217 | 1218 | 1222 |
Publicfunction WriteSingle(const Item: Single): PLightFileStream; inline;
1219 |

1220 | Writes a single instance of Single from Item to the underlying file at the current position, possibly overwriting existing data.

1221 |
1223 | 1224 | 1225 | 1226 | 1227 | 1228 | 1232 |
Publicfunction WriteSmallInt(const Item: SmallInt): PLightFileStream; inline;
1229 |

1230 | Writes a single instance of SmallInt from Item to the underlying file at the current position, possibly overwriting existing data.

1231 |
1233 | 1234 | 1235 | 1236 | 1237 | 1238 | 1242 |
Publicfunction WriteType<T>(constref Item: T): PLightFileStream; inline;
1239 |

1240 | Writes a single instance of T from Item to the underlying file at the current position, possibly overwriting existing data.

1241 |
1243 | 1244 | 1245 | 1246 | 1247 | 1248 | 1252 |
Publicfunction WriteTypedBuffer<T>(constref Buffer: T; const ItemCount: SizeInt): PLightFileStream; inline;
1249 |

1250 | Assumes Buffer is something like the first value of an array of T. Writes ItemCount items from it to the underlying file at the current position, possibly overwriting existing data.

1251 |
1253 | 1254 | 1255 | 1256 | 1257 | 1258 | 1262 |
Publicfunction WriteUnicodeChar(const Item: UnicodeChar): PLightFileStream; inline;
1259 |

1260 | Writes a single instance of UnicodeChar from Item to the underlying file at the current position, possibly overwriting existing data.

1261 |
1263 | 1264 | 1265 | 1266 | 1267 | 1268 | 1272 |
Publicfunction WriteUnicodeString(const Item: UnicodeString): PLightFileStream; inline;
1269 |

1270 | Writes a single instance of UnicodeString from Item to the underlying file at the current position, possibly overwriting existing data.

1271 |
1273 | 1274 | 1275 | 1276 | 1277 | 1278 | 1282 |
Publicfunction WriteWideChar(const Item: WideChar): PLightFileStream; inline;
1279 |

1280 | Writes a single instance of WideChar from Item to the underlying file at the current position, possibly overwriting existing data.

1281 |
1283 | 1284 | 1285 | 1286 | 1287 | 1288 | 1292 |
Publicfunction WriteWideString(const Item: WideString): PLightFileStream; inline;
1289 |

1290 | Writes a single instance of WideString from Item to the underlying file at the current position, possibly overwriting existing data.

1291 |
1293 | 1294 | 1295 | 1296 | 1297 | 1298 | 1302 |
Publicfunction WriteWord(const Item: Word): PLightFileStream; inline;
1299 |

1300 | Writes a single instance of Word from Item to the underlying file at the current position, possibly overwriting existing data.

1301 |
1303 | 1304 | 1305 | 1306 | 1307 | 1308 | 1312 |
Publicprocedure Close; inline;
1309 |

1310 | Closes the underlying file. Does not return a self-pointer, as it should always be the last method called.

1311 |
1313 |

Properties

1314 | 1315 | 1316 | 1317 | 1318 | 1319 | 1323 |
Publicproperty IsOpen: Boolean read FOpen;
1320 |

1321 | Indicates directly whether or not the underlying file is open.

1322 |
1324 |
Generated by PasDoc 0.15.0. 1325 | 1326 |
1327 | -------------------------------------------------------------------------------- /DocsHTML/LightFileStream.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | LightFileStream 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
17 |

Unit LightFileStream

18 |
19 |
Uses
Functions and Procedures
Constants
Variables
20 |

Description

21 |

22 | Implements a lightweight, high-performance, non-allocating advanced-record-based wrapper around the SysUtils file handling routines as an alternative to Classes.TFileStream.

23 |

Overview

24 |

Classes, Interfaces, Objects and Records

25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 35 | 36 |
NameDescription
Record TLightFileStream The sole type implemented by this unit so far. 33 | 34 |

Returns a pointer to itself from all functions to avoid unnecessary allocation or copying and to allow for a convenient "method chaining" API.

37 |

Types

38 | 39 | 40 | 41 | 42 |
PLightFileStream = ˆTLightFileStream;
43 |

Description

44 |

Types

45 | 46 | 47 | 48 | 49 | 53 |
PLightFileStream = ˆTLightFileStream;
50 |

51 | Type alias for a pointer to the TLightFileStream type.

52 |
54 |
Generated by PasDoc 0.15.0. 55 | 56 |
57 | -------------------------------------------------------------------------------- /DocsHTML/automated.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Akira13641/TLightFileStream/cd03620bd4fe8a344543236cbcda6629c201df2a/DocsHTML/automated.gif -------------------------------------------------------------------------------- /DocsHTML/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | All Units 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
17 |

All Units

18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
NameDescription
LightFileStream

Implements a lightweight, high-performance, non-allocating advanced-record-based wrapper around the SysUtils file handling routines as an alternative to Classes.TFileStream.

28 |
Generated by PasDoc 0.15.0. 29 | 30 |
31 | -------------------------------------------------------------------------------- /DocsHTML/legend.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Legend 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
17 |

Legend

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 |
MarkerVisibility
Strict PrivateStrict Private
PrivatePrivate
Strict ProtectedStrict Protected
ProtectedProtected
PublicPublic
PublishedPublished
AutomatedAutomated
ImplicitImplicit
56 |
Generated by PasDoc 0.15.0. 57 | 58 |
59 | -------------------------------------------------------------------------------- /DocsHTML/pasdoc.css: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 1998-2018 PasDoc developers. 3 | 4 | This file is part of "PasDoc". 5 | 6 | "PasDoc" is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | "PasDoc" is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with "PasDoc"; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 19 | 20 | ---------------------------------------------------------------------------- 21 | */ 22 | 23 | body, html, table.container { 24 | margin: 0; 25 | padding: 0; 26 | } 27 | 28 | body { 29 | font-family: Verdana,Arial; 30 | color: black; 31 | background-color: white; 32 | } 33 | 34 | table.container { 35 | width: 100%; 36 | border-spacing: 0; 37 | } 38 | table.container td { 39 | vertical-align: top; 40 | } 41 | 42 | td.navigation { 43 | width: 200px; 44 | color: white; 45 | background-color: #787878; 46 | margin: 0; 47 | /* padding-bottom is a little larger, to make navigation column have some 48 | nice height even when td.content column is very small. */ 49 | padding: 1em 1em 100px 1em; 50 | } 51 | td.navigation p { padding: 0; } 52 | td.navigation h2 { margin-top: 0; } 53 | 54 | td.content { padding: 1em; } 55 | td.content h1 { margin-top: 0; } 56 | 57 | img { border:0px; } 58 | 59 | hr { 60 | border-bottom: medium none; 61 | border-top: thin solid #888; 62 | } 63 | 64 | a:link {color:#C91E0C; text-decoration: none; } 65 | a:visited {color:#7E5C31; text-decoration: none; } 66 | a:hover {text-decoration: underline; } 67 | a:active {text-decoration: underline; } 68 | 69 | a.navigation:link { color: white; text-decoration: none; } 70 | a.navigation:visited { color: white; text-decoration: none; } 71 | a.navigation:hover { color: white; font-weight: bold; text-decoration: none; } 72 | a.navigation:active { color: white; text-decoration: none; } 73 | 74 | a.bold:link {color:#C91E0C; text-decoration: none; font-weight:bold; } 75 | a.bold:visited {color:#7E5C31; text-decoration: none; font-weight:bold; } 76 | a.bold:hover {text-decoration: underline; font-weight:bold; } 77 | a.bold:active {text-decoration: underline; font-weight:bold; } 78 | 79 | a.section {color: green; text-decoration: none; font-weight: bold; } 80 | a.section:hover {color: green; text-decoration: underline; font-weight: bold; } 81 | 82 | ul.useslist a:link {color:#C91E0C; text-decoration: none; font-weight:bold; } 83 | ul.useslist a:visited {color:#7E5C31; text-decoration: none; font-weight:bold; } 84 | ul.useslist a:hover {text-decoration: underline; font-weight:bold; } 85 | ul.useslist a:active {text-decoration: underline; font-weight:bold; } 86 | 87 | ul.hierarchy { list-style-type:none; } 88 | ul.hierarchylevel { list-style-type:none; } 89 | 90 | p.unitlink a:link {color:#C91E0C; text-decoration: none; font-weight:bold; } 91 | p.unitlink a:visited {color:#7E5C31; text-decoration: none; font-weight:bold; } 92 | p.unitlink a:hover {text-decoration: underline; font-weight:bold; } 93 | p.unitlink a:active {text-decoration: underline; font-weight:bold; } 94 | 95 | tr.list { background: #FFBF44; } 96 | tr.list2 { background: #FFC982; } 97 | tr.listheader { background: #C91E0C; color: white; } 98 | 99 | table.wide_list { border-spacing:2px; width:100%; } 100 | table.wide_list td { vertical-align:top; padding:4px; } 101 | 102 | table.markerlegend { width:auto; } 103 | table.markerlegend td.legendmarker { text-align:center; } 104 | 105 | .sections { background:white; } 106 | .sections .one_section { 107 | background:lightgray; 108 | display: inline-block; 109 | margin: 0.2em; 110 | padding: 0.5em 1em; 111 | } 112 | 113 | table.summary td.itemcode { width:100%; } 114 | table.detail td.itemcode { width:100%; } 115 | 116 | td.itemname {white-space:nowrap; } 117 | td.itemunit {white-space:nowrap; } 118 | td.itemdesc { width:100%; } 119 | 120 | div.nodescription { color:red; } 121 | dl.parameters dt { color:blue; } 122 | 123 | /* Various browsers have various default styles for
, 124 | sometimes ugly for our purposes, so it's best to set things 125 | like font-size and font-weight in out pasdoc.css explicitly. */ 126 | h6.description_section { 127 | /* font-size 100% means that it has the same font size as the 128 | parent element, i.e. normal description text */ 129 | font-size: 100%; 130 | font-weight: bold; 131 | /* By default browsers usually have some large margin-bottom and 132 | margin-top for tags. In our case, margin-bottom is 133 | unnecessary, we want to visually show that description_section 134 | is closely related to content below. In this situation 135 | (where the font size is just as a normal text), smaller bottom 136 | margin seems to look good. */ 137 | margin-top: 1.4em; 138 | margin-bottom: 0em; 139 | } 140 | 141 | /* Style applied to Pascal code in documentation 142 | (e.g. produced by @longcode tag) } */ 143 | span.pascal_string { color: #000080; } 144 | span.pascal_keyword { font-weight: bolder; } 145 | span.pascal_comment { color: #000080; font-style: italic; } 146 | span.pascal_compiler_comment { color: #008000; } 147 | span.pascal_numeric { } 148 | span.pascal_hex { } 149 | 150 | p.hint_directive { color: red; } 151 | 152 | input#search_text { } 153 | input#search_submit_button { } 154 | 155 | acronym.mispelling { background-color: #ffa; } 156 | 157 | /* Actually this reduces vertical space between *every* paragraph 158 | inside list with @itemSpacing(compact). 159 | While we would like to reduce this space only for the 160 | top of 1st and bottom of last paragraph within each list item. 161 | But, well, user probably will not do any paragraph breaks 162 | within a list with @itemSpacing(compact) anyway, so it's 163 | acceptable solution. */ 164 | ul.compact_spacing p { margin-top: 0em; margin-bottom: 0em; } 165 | ol.compact_spacing p { margin-top: 0em; margin-bottom: 0em; } 166 | dl.compact_spacing p { margin-top: 0em; margin-bottom: 0em; } 167 | 168 | /* Style for table created by @table tags: 169 | just some thin border. 170 | 171 | This way we have some borders around the cells 172 | (so cells are visibly separated), but the border 173 | "blends with the background" so it doesn't look too ugly. 174 | Hopefully it looks satisfactory in most cases and for most 175 | people. 176 | 177 | We add padding for cells, otherwise they look too close. 178 | This is normal thing to do when border-collapse is set to 179 | collapse (because this eliminates spacing between cells). 180 | */ 181 | table.table_tag { border-collapse: collapse; } 182 | table.table_tag td { border: 1pt solid gray; padding: 0.3em; } 183 | table.table_tag th { border: 1pt solid gray; padding: 0.3em; } 184 | 185 | table.detail { 186 | border: 1pt solid gray; 187 | margin-top: 0.3em; 188 | margin-bottom: 0.3em; 189 | } 190 | 191 | .search-form { white-space: nowrap; } 192 | .search-input, .search-button { display: inline-block; vertical-align: middle; } 193 | 194 | /* Do not make extra vertical space at the beginning/end of table cells. 195 | We need ">" selector, to not change paragraphs inside lists inside 196 | table cells. */ 197 | table.table_tag td > p:first-child, 198 | table.table_tag th > p:first-child, 199 | td.itemdesc > p:first-child { margin-top: 0em; } 200 | 201 | table.table_tag td > p:last-child, 202 | table.table_tag th > p:last-child, 203 | td.itemdesc > p:last-child { margin-bottom: 0em; } 204 | -------------------------------------------------------------------------------- /DocsHTML/private.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Akira13641/TLightFileStream/cd03620bd4fe8a344543236cbcda6629c201df2a/DocsHTML/private.gif -------------------------------------------------------------------------------- /DocsHTML/protected.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Akira13641/TLightFileStream/cd03620bd4fe8a344543236cbcda6629c201df2a/DocsHTML/protected.gif -------------------------------------------------------------------------------- /DocsHTML/public.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Akira13641/TLightFileStream/cd03620bd4fe8a344543236cbcda6629c201df2a/DocsHTML/public.gif -------------------------------------------------------------------------------- /DocsHTML/published.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Akira13641/TLightFileStream/cd03620bd4fe8a344543236cbcda6629c201df2a/DocsHTML/published.gif -------------------------------------------------------------------------------- /Example/LightFileStreamExample.lpi: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | <UseAppBundle Value="False"/> 16 | <ResourceType Value="res"/> 17 | </General> 18 | <BuildModes Count="2"> 19 | <Item1 Name="Release" Default="True"/> 20 | <Item2 Name="Debug"> 21 | <CompilerOptions> 22 | <Version Value="11"/> 23 | <PathDelim Value="\"/> 24 | <Target> 25 | <Filename Value="LightFileStreamExampleDebug"/> 26 | </Target> 27 | <SearchPaths> 28 | <IncludeFiles Value="$(ProjOutDir)"/> 29 | <UnitOutputDirectory Value="libdebug\$(TargetCPU)-$(TargetOS)"/> 30 | </SearchPaths> 31 | <Parsing> 32 | <SyntaxOptions> 33 | <SyntaxMode Value="Delphi"/> 34 | </SyntaxOptions> 35 | </Parsing> 36 | <CodeGeneration> 37 | <Optimizations> 38 | <OptimizationLevel Value="0"/> 39 | </Optimizations> 40 | </CodeGeneration> 41 | <Linking> 42 | <Debugging> 43 | <DebugInfoType Value="dsDwarf2"/> 44 | <UseHeaptrc Value="True"/> 45 | </Debugging> 46 | </Linking> 47 | <Other> 48 | <CustomOptions Value="-b -bl -godwarfsets -godwarfmethodclassprefix -dDEBUG"/> 49 | </Other> 50 | </CompilerOptions> 51 | </Item2> 52 | </BuildModes> 53 | <PublishOptions> 54 | <Version Value="2"/> 55 | <UseFileFilters Value="True"/> 56 | </PublishOptions> 57 | <RunParams> 58 | <FormatVersion Value="2"/> 59 | <Modes Count="0"/> 60 | </RunParams> 61 | <RequiredPackages Count="1"> 62 | <Item1> 63 | <PackageName Value="LazLightFileStream"/> 64 | </Item1> 65 | </RequiredPackages> 66 | <Units Count="1"> 67 | <Unit0> 68 | <Filename Value="LightFileStreamExample.lpr"/> 69 | <IsPartOfProject Value="True"/> 70 | </Unit0> 71 | </Units> 72 | </ProjectOptions> 73 | <CompilerOptions> 74 | <Version Value="11"/> 75 | <PathDelim Value="\"/> 76 | <Target> 77 | <Filename Value="LightFileStreamExample"/> 78 | </Target> 79 | <SearchPaths> 80 | <IncludeFiles Value="$(ProjOutDir)"/> 81 | <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> 82 | </SearchPaths> 83 | <Parsing> 84 | <SyntaxOptions> 85 | <SyntaxMode Value="Delphi"/> 86 | </SyntaxOptions> 87 | </Parsing> 88 | <CodeGeneration> 89 | <SmartLinkUnit Value="True"/> 90 | <Optimizations> 91 | <OptimizationLevel Value="4"/> 92 | </Optimizations> 93 | </CodeGeneration> 94 | <Linking> 95 | <Debugging> 96 | <GenerateDebugInfo Value="False"/> 97 | <UseLineInfoUnit Value="False"/> 98 | <StripSymbols Value="True"/> 99 | </Debugging> 100 | <LinkSmart Value="True"/> 101 | </Linking> 102 | <Other> 103 | <CustomOptions Value="-Co- -CO- -Cr- -Cr- -g-"/> 104 | </Other> 105 | </CompilerOptions> 106 | <Debugging> 107 | <Exceptions Count="3"> 108 | <Item1> 109 | <Name Value="EAbort"/> 110 | </Item1> 111 | <Item2> 112 | <Name Value="ECodetoolError"/> 113 | </Item2> 114 | <Item3> 115 | <Name Value="EFOpenError"/> 116 | </Item3> 117 | </Exceptions> 118 | </Debugging> 119 | </CONFIG> 120 | -------------------------------------------------------------------------------- /Example/LightFileStreamExample.lpr: -------------------------------------------------------------------------------- 1 | program LightFileStreamExample; 2 | 3 | {$mode Delphi}{$H+}{$J-}{$I-}{$R-} 4 | 5 | uses SysUtils, LightFileStream; 6 | 7 | type 8 | TDataRec = record 9 | S: Single; 10 | B: Boolean; 11 | C: AnsiChar; 12 | end; 13 | 14 | const 15 | DAA: array[0..5] of Double = (1.11, 2.22, 3.33, 4.44, 5.55, 6.66); 16 | DRA: TDataRec = (S: 1.0; B: True; C: 'A'); 17 | 18 | var 19 | D: Double; 20 | DAB: array of Double; 21 | SA: AnsiString = 'hello'; 22 | SB: AnsiString = ' '; 23 | IA: SizeInt; 24 | C: Char; 25 | CAA: array[0..5] of Char = (#0, #0, #0, #0, #0, #0); 26 | H: UnicodeString = ' '; 27 | G: UnicodeString = ' '; 28 | IB: LongInt; 29 | FA: Single; 30 | DRB: TDataRec; 31 | LS: TLightFileStream; 32 | PLS: PLightFileStream; 33 | 34 | begin 35 | SetLength(DAB, 28); 36 | 37 | // If using the library in a {$mode ObjFPC} project, you can still use {$modeswitch AutoDeref} 38 | // to avoid having to manually dereference after each chained function call. 39 | 40 | TLightFileStream.Create('Example1.txt') 41 | .WriteTypedBuffer<Double>(DAA[0], 6) 42 | .WriteTypedBuffer<Double>(DAA[0], 6) 43 | .SeekFromBeginning(0) 44 | .AppendTypedBuffer<Double>(DAA[0], 6) 45 | .WritePointerBuffer(@DAA[0], SizeOf(Double) * 6) 46 | .WriteDouble(99.99) 47 | .SeekFromBeginning(0) 48 | .AppendDouble(128.12) 49 | .WriteType<Double>(77.77) 50 | .WriteDouble(345.34) 51 | .ChangeFileStateTo(fsReading) 52 | .ReadPointerBuffer(@DAB[0], SizeOf(Double) * 28) 53 | .Close(); 54 | for D in DAB do WriteLn(D : 0 : 2); 55 | 56 | TLightFileStream.Create('Example2.txt') 57 | .WriteAnsiString(SA) 58 | .ChangeFileStateTo(fsReading) 59 | .ReadAnsiString(SB, 5) 60 | .Close(); 61 | WriteLn(SB); 62 | 63 | TLightFileStream.Create('Example3.txt') 64 | .WriteQWord(1) 65 | .WriteDouble(2.0) 66 | .WriteSingle(3.9) 67 | .WriteType<QWord>(4) 68 | .WriteType<Double>(5.7) 69 | .WriteType<Single>(6.8) 70 | .SeekFromBeginning(0) 71 | .LogSize() 72 | .LogPosition() 73 | .GetSize(IA) 74 | .SeekFromBeginning(IA div 2) 75 | .Truncate() 76 | .LogSize() 77 | .LogPosition() 78 | .Close(); 79 | 80 | TLightFileStream.Create('Example4.txt') 81 | .FillWith<Char>('Z', 6) 82 | .ChangeFileStateTo(fsReading) 83 | .ReadTypedBuffer<Char>(CAA[0], 6) 84 | .Close(); 85 | for C in CAA do WriteLn(C); 86 | 87 | // The library can also of course be used without fully chaining everything. 88 | // The next line makes the LS variable our base non-pointer instance of the TLightFileStream record. 89 | LS := TLightFileStream.Create('Example5.txt'); 90 | 91 | // It's fine to call any of the functions that return a self-pointer without the result connecting to anything. 92 | // In that case, the self-pointer is just discarded. The next line shows an example of this. 93 | LS.WriteUnicodeString('hello') 94 | .WriteUnicodeString('goodbye'); 95 | 96 | // You can also have a named PLightFileStream variable and assign the self-pointer results to it, as shown on the next line. 97 | PLS := LS.WriteLongInt(1) 98 | .WriteSingle(2.94) 99 | .WriteType<TDataRec>(DRA); 100 | 101 | // At this point, accessing either LS or PLS does the same thing, as PLS is just a pointer to LS. 102 | // So on the next line, we'll do something similar to the one above, but both starting from and returning into PLS. 103 | PLS := PLS.ChangeFileStateTo(fsReading) 104 | .ReadUnicodeString(H, 5) 105 | .ReadUnicodeString(G, 7) 106 | .ReadLongInt(IB) 107 | .ReadSingle(FA) 108 | .ReadType<TDataRec>(DRB); 109 | 110 | // Next we'll display the values... 111 | WriteLn(H); 112 | WriteLn(G); 113 | WriteLn(IB); 114 | WriteLn(FA : 0 : 2); 115 | with DRB do begin 116 | WriteLn(S : 0 : 2); 117 | WriteLn(B); 118 | WriteLn(C); 119 | end; 120 | 121 | // And finally we'll close the file through PLS. 122 | PLS.Close(); 123 | 124 | DeleteFile('Example1.txt'); 125 | DeleteFile('Example2.txt'); 126 | DeleteFile('Example3.txt'); 127 | DeleteFile('Example4.txt'); 128 | DeleteFile('Example5.txt'); 129 | end. 130 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Akira13641 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LazLightFileStream.lpk: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="UTF-8"?> 2 | <CONFIG> 3 | <Package Version="4"> 4 | <PathDelim Value="\"/> 5 | <Name Value="LazLightFileStream"/> 6 | <Author Value="Akira1364"/> 7 | <CompilerOptions> 8 | <Version Value="11"/> 9 | <PathDelim Value="\"/> 10 | <SearchPaths> 11 | <OtherUnitFiles Value="Source"/> 12 | <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> 13 | </SearchPaths> 14 | <Parsing> 15 | <SyntaxOptions> 16 | <SyntaxMode Value="Delphi"/> 17 | </SyntaxOptions> 18 | </Parsing> 19 | <CodeGeneration> 20 | <SmartLinkUnit Value="True"/> 21 | <Optimizations> 22 | <OptimizationLevel Value="3"/> 23 | </Optimizations> 24 | </CodeGeneration> 25 | <Linking> 26 | <Debugging> 27 | <GenerateDebugInfo Value="False"/> 28 | <UseLineInfoUnit Value="False"/> 29 | </Debugging> 30 | </Linking> 31 | <Other> 32 | <CustomOptions Value="$(IDEBuildOptions)"/> 33 | </Other> 34 | </CompilerOptions> 35 | <Description Value="Implements a lightweight, high-performance, non-allocating advanced-record-based wrapper around the SysUtils file handling routines as an alternative to Classes.TFileStream."/> 36 | <License Value="MIT License 37 | 38 | Copyright (c) 2019 Akira13641 39 | 40 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 41 | 42 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 43 | 44 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."/> 45 | <Version Major="1" Minor="2"/> 46 | <Files Count="1"> 47 | <Item1> 48 | <Filename Value="Source\LightFileStream.pas"/> 49 | <UnitName Value="LightFileStream"/> 50 | </Item1> 51 | </Files> 52 | <UsageOptions> 53 | <UnitPath Value="$(PkgOutDir)"/> 54 | </UsageOptions> 55 | <PublishOptions> 56 | <Version Value="2"/> 57 | <UseFileFilters Value="True"/> 58 | </PublishOptions> 59 | </Package> 60 | </CONFIG> 61 | -------------------------------------------------------------------------------- /LazLightFileStream.pas: -------------------------------------------------------------------------------- 1 | { This file was automatically created by Lazarus. Do not edit! 2 | This source is only used to compile and install the package. 3 | } 4 | 5 | unit LazLightFileStream; 6 | 7 | {$warn 5023 off : no warning about unused units} 8 | interface 9 | 10 | uses 11 | LightFileStream; 12 | 13 | implementation 14 | 15 | end. 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TLightFileStream 2 | Implements a lightweight, high-performance, non-allocating advanced-record-based wrapper around the SysUtils file handling routines as an alternative to Classes.TFileStream. 3 | 4 | Compatible with Free Pascal 3.1.1+ 5 | -------------------------------------------------------------------------------- /Source/GenerateCHMDocs.bat: -------------------------------------------------------------------------------- 1 | rm -rf temp && ^ 2 | rm -rf ../DocsCHM && ^ 3 | mkdir temp && ^ 4 | pasdoc -Etemp --auto-link --visible-members strictprivate,private,strictprotected,protected,public,published,automated --sort=structures,constants,functions,types,variables,uses-clauses,record-fields,non-record-fields,methods,properties --format=htmlhelp -N LightFileStream LightFileStream.pas && ^ 5 | cd temp && ^ 6 | chmcmd --html-scan --verbosity 0 LightFileStream.hhp && ^ 7 | cd .. && ^ 8 | mkdir ..\DocsCHM && ^ 9 | mv temp/LightFileStream.chm ../DocsCHM/LightFileStream.chm && ^ 10 | rm -rf temp -------------------------------------------------------------------------------- /Source/GenerateCHMDocs.sh: -------------------------------------------------------------------------------- 1 | rm -rf ./temp && \ 2 | rm -rf ../DocsCHM && \ 3 | mkdir ./temp && \ 4 | pasdoc -E./temp --auto-link --visible-members strictprivate,private,strictprotected,protected,public,published,automated --sort=structures,constants,functions,types,variables,uses-clauses,record-fields,non-record-fields,methods,properties --format=htmlhelp -N LightFileStream ./LightFileStream.pas && \ 5 | cd ./temp && chmcmd --html-scan --verbosity 0 ./LightFileStream.hhp && \ 6 | cd .. && \ 7 | mkdir ../DocsCHM && \ 8 | mv ./temp/LightFileStream.chm ../DocsCHM/LightFileStream.chm && \ 9 | rm -rf ./temp -------------------------------------------------------------------------------- /Source/GenerateHTMLDocs.bat: -------------------------------------------------------------------------------- 1 | rm -rf temp && ^ 2 | rm -rf ../DocsHTML && ^ 3 | mkdir temp && ^ 4 | pasdoc -Etemp --auto-link --use-tipue-search --visible-members strictprivate,private,strictprotected,protected,public,published,automated --sort=structures,constants,functions,types,variables,uses-clauses,record-fields,non-record-fields,methods,properties --format=html -N LightFileStream LightFileStream.pas && ^ 5 | mv temp ../DocsHTML && ^ 6 | rm -rf temp -------------------------------------------------------------------------------- /Source/GenerateHTMLDocs.sh: -------------------------------------------------------------------------------- 1 | rm -rf ./temp && \ 2 | rm -rf ../DocsHTML && \ 3 | mkdir ./temp && \ 4 | pasdoc -E./temp --auto-link --use-tipue-search --visible-members strictprivate,private,strictprotected,protected,public,published,automated --sort=structures,constants,functions,types,variables,uses-clauses,record-fields,non-record-fields,methods,properties --format=html -N LightFileStream ./LightFileStream.pas && \ 5 | mv ./temp ../DocsHTML && \ 6 | rm -rf ./temp -------------------------------------------------------------------------------- /Source/LightFileStream.pas: -------------------------------------------------------------------------------- 1 | {@abstract(Implements a lightweight, high-performance, non-allocating advanced-record-based wrapper 2 | around the SysUtils file handling routines as an alternative to Classes.TFileStream.)} 3 | 4 | unit LightFileStream; 5 | 6 | {$mode Delphi}{$H+}{$J-}{$I-}{$R-} 7 | 8 | {Uncomment LIGHTFILESTREAM_NOCHECKS when building production releases of thoroughly tested software.} 9 | {.$define LIGHTFILESTREAM_NOCHECKS} 10 | 11 | interface 12 | 13 | uses SysUtils; 14 | 15 | type 16 | {Type alias for a pointer to the TLightFileStream type.} 17 | PLightFileStream = ^TLightFileStream; 18 | 19 | {@abstract( 20 | The sole type implemented by this unit so far. 21 | 22 | Returns a pointer to itself from all functions to avoid unnecessary allocation or copying 23 | and to allow for a convenient "method chaining" API.)} 24 | TLightFileStream = record 25 | public type 26 | (*Determines whether read or write operations are actively accepted. 27 | 28 | All functions return immediately without doing anything if the current state is "wrong" relative to them, 29 | unless @code({$define LIGHTFILESTREAM_NOCHECKS}) is set, which improves performance but is somewhat less "safe."*) 30 | TFileState = (fsReading, fsWriting); 31 | strict private 32 | {The name of the underlying file on disk.} 33 | FFileName: PChar; 34 | {The handle of the underlying file on disk.} 35 | FHandle: THandle; 36 | (*Indicates whether the file is @noAutoLink(open) and can be accessed at all. 37 | 38 | All functions return immediately without doing anything in the event that this is false, 39 | unless @code({$define LIGHTFILESTREAM_NOCHECKS}) is set, which improves performance but is somewhat less "safe."*) 40 | FOpen: Boolean; 41 | {A private instance of TFileState, used as described above.} 42 | FState: TFileState; 43 | public 44 | {Assumes @code(FileName) does not yet exist on disk. Calls @code(FileCreate()) internally. 45 | FState is then set to fsWriting, and FOpen is set to True.} 46 | class function Create(const FileName: PChar): TLightFileStream; static; {$IFNDEF DEBUG}inline;{$ENDIF} 47 | {Assumes @code(FileName) already exists on disk. Calls @code(FileOpen()) with either @code(fmOpenRead) or @code(fmOpenWrite) internally based on the provided @code(InitialState) value. 48 | 49 | FState is then set to @code(InitialState), and FOpen is set to True.} 50 | class function Open(const FileName: PChar; const InitialState: TFileState): TLightFileStream; static; {$IFNDEF DEBUG}inline;{$ENDIF} 51 | {Closes the underlying file. Does not return a self-pointer, as it should always be the last method called.} 52 | procedure Close; {$IFNDEF DEBUG}inline;{$ENDIF} 53 | {Calls @code(FileClose()) on FHandle, then calls @code(FileOpen()) with either @code(fmOpenRead) or @code(fmOpenWrite) 54 | internally based on the provided @code(State) value. FState is then set to @code(State).} 55 | function ChangeFileStateTo(const State: TFileState): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 56 | {Sets the current @noAutoLink(position) of the underlying file to @code(ToPosition), relative to 0.} 57 | function SeekFromBeginning(const ToPosition: SizeInt): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 58 | {Sets the current @noAutoLink(position) of the underlying file to @code(ToPosition), relative to itself.} 59 | function SeekFromCurrent(const ToPosition: SizeInt): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 60 | {Sets the current @noAutoLink(position) of the underlying file to @code(ToPosition), relative to the end of the file.} 61 | function SeekFromEnd(const ToPosition: SizeInt): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 62 | {Returns the @noAutoLink(size) in bytes of the underlying file in @code(TheSize), and a self-pointer from the function itself.} 63 | function GetSize(out TheSize: SizeInt): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 64 | {Returns the @noAutoLink(size) in bytes of the underlying file.} 65 | function PutSize: SizeInt; {$IFNDEF DEBUG}inline;{$ENDIF} 66 | {Calls GetSize() internally and displays the value with @code(WriteLn()).} 67 | function LogSize: PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 68 | {Returns the current @noAutoLink(position) of the underlying file in @code(ThePosition), and a self-pointer from the function itself.} 69 | function GetPosition(out ThePosition: SizeInt): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 70 | {Returns the current @noAutoLink(position) of the underlying file.} 71 | function PutPosition: SizeInt; {$IFNDEF DEBUG}inline;{$ENDIF} 72 | {Calls GetPosition() internally and displays the value with @code(WriteLn()).} 73 | function LogPosition: PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 74 | {Truncates the underlying file at the current position.} 75 | function Truncate: PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 76 | {Reads a single instance of T into @code(Item) from the underlying file at the current @noAutoLink(position).} 77 | function ReadType<T>(var Item: T): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 78 | {Writes a single instance of T from @code(Item) to the underlying file at the current @noAutoLink(position), possibly overwriting existing data.} 79 | function WriteType<T>(constref Item: T): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 80 | {Writes a single instance of T from @code(Item) to the underlying file at the last @noAutoLink(position), behind any existing data.} 81 | function AppendType<T>(constref Item: T): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 82 | {Writes @code(NumInstances) instances of @code(Value) to the underlying file at the current position.} 83 | function FillWith<T>(constref Value: T; const NumInstances: SizeUInt): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 84 | {Assumes @code(Buffer) is something like the first value of an array of T. Reads @code(ItemCount) items into it from the underlying file at the current @noAutoLink(position).} 85 | function ReadTypedBuffer<T>(var Buffer: T; const ItemCount: SizeInt): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 86 | {Assumes @code(Buffer) is something like the first value of an array of T. Writes @code(ItemCount) items from it to the underlying file at the current @noAutoLink(position), possibly overwriting existing data.} 87 | function WriteTypedBuffer<T>(constref Buffer: T; const ItemCount: SizeInt): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 88 | {Assumes @code(Buffer) is something like the first value of an array of T. Writes @code(ItemCount) items from it to the underlying file at the last @noAutoLink(position), behind any existing data.} 89 | function AppendTypedBuffer<T>(constref Buffer: T; const ItemCount: SizeInt): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 90 | {Assumes @code(Buffer) is pointing to something like the first value of an array of any type. Reads @code(NumBytesToRead) bytes into it from the underlying file at the current @noAutoLink(position).} 91 | function ReadPointerBuffer(const Buffer: Pointer; const NumBytesToRead: SizeInt): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 92 | {Assumes @code(Buffer) is pointing to something like the first value of an array of any type. 93 | 94 | Writes @code(NumBytesToWrite) bytes from it to the underlying file at the current @noAutoLink(position), possibly overwriting existing data.} 95 | function WritePointerBuffer(const Buffer: Pointer; const NumBytesToWrite: SizeInt): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 96 | {Assumes @code(Buffer) is pointing to something like the first value of an array of any type. Writes @code(NumBytesToWrite) bytes from it to the underlying file at the last @noAutoLink(position), behind any existing data.} 97 | function AppendPointerBuffer(const Buffer: Pointer; const NumBytesToWrite: SizeInt): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 98 | {Reads a single instance of Byte into @code(Item) from the underlying file at the current @noAutoLink(position).} 99 | function ReadByte(var Item: Byte): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 100 | {Writes a single instance of Byte from @code(Item) to the underlying file at the current @noAutoLink(position), possibly overwriting existing data.} 101 | function WriteByte(const Item: Byte): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 102 | {Writes a single instance of Byte from @code(Item) to the underlying file at the last @noAutoLink(position), behind any existing data.} 103 | function AppendByte(const Item: Byte): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 104 | {Reads a single instance of Word into @code(Item) from the underlying file at the current @noAutoLink(position).} 105 | function ReadWord(var Item: Word): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 106 | {Writes a single instance of Word from @code(Item) to the underlying file at the current @noAutoLink(position), possibly overwriting existing data.} 107 | function WriteWord(const Item: Word): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 108 | {Writes a single instance of Word from @code(Item) to the underlying file at the last @noAutoLink(position), behind any existing data.} 109 | function AppendWord(const Item: Word): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 110 | {Reads a single instance of LongWord into @code(Item) from the underlying file at the current @noAutoLink(position).} 111 | function ReadLongWord(var Item: LongWord): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 112 | {Writes a single instance of LongWord from @code(Item) to the underlying file at the current @noAutoLink(position), possibly overwriting existing data.} 113 | function WriteLongWord(const Item: LongWord): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 114 | {Writes a single instance of LongWord from @code(Item) to the underlying file at the last @noAutoLink(position), behind any existing data.} 115 | function AppendLongWord(const Item: LongWord): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 116 | {Reads a single instance of QWord into @code(Item) from the underlying file at the current @noAutoLink(position).} 117 | function ReadQWord(var Item: QWord): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 118 | {Writes a single instance of QWord from @code(Item) to the underlying file at the current @noAutoLink(position), possibly overwriting existing data.} 119 | function WriteQWord(const Item: QWord): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 120 | {Writes a single instance of QWord from @code(Item) to the underlying file at the last @noAutoLink(position), behind any existing data.} 121 | function AppendQWord(const Item: QWord): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 122 | {Reads a single instance of ShortInt into @code(Item) from the underlying file at the current @noAutoLink(position).} 123 | function ReadShortInt(var Item: ShortInt): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 124 | {Writes a single instance of ShortInt from @code(Item) to the underlying file at the current @noAutoLink(position), possibly overwriting existing data.} 125 | function WriteShortInt(const Item: ShortInt): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 126 | {Writes a single instance of ShortInt from @code(Item) to the underlying file at the last @noAutoLink(position), behind any existing data.} 127 | function AppendShortInt(const Item: ShortInt): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 128 | {Reads a single instance of SmallInt into @code(Item) from the underlying file at the current @noAutoLink(position).} 129 | function ReadSmallInt(var Item: SmallInt): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 130 | {Writes a single instance of SmallInt from @code(Item) to the underlying file at the current @noAutoLink(position), possibly overwriting existing data.} 131 | function WriteSmallInt(const Item: SmallInt): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 132 | {Writes a single instance of SmallInt from @code(Item) to the underlying file at the last @noAutoLink(position), behind any existing data.} 133 | function AppendSmallInt(const Item: SmallInt): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 134 | {Reads a single instance of LongInt into @code(Item) from the underlying file at the current @noAutoLink(position).} 135 | function ReadLongInt(var Item: LongInt): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 136 | {Writes a single instance of LongInt from @code(Item) to the underlying file at the current @noAutoLink(position), possibly overwriting existing data.} 137 | function WriteLongInt(const Item: LongInt): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 138 | {Writes a single instance of LongInt from @code(Item) to the underlying file at the last @noAutoLink(position), behind any existing data.} 139 | function AppendLongInt(const Item: LongInt): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 140 | {Reads a single instance of Int64 into @code(Item) from the underlying file at the current @noAutoLink(position).} 141 | function ReadInt64(var Item: Int64): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 142 | {Writes a single instance of Int64 from @code(Item) to the underlying file at the current @noAutoLink(position), possibly overwriting existing data.} 143 | function WriteInt64(const Item: Int64): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 144 | {Writes a single instance of Int64 from @code(Item) to the underlying file at the last @noAutoLink(position), behind any existing data.} 145 | function AppendInt64(const Item: Int64): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 146 | {Reads a single instance of Single into @code(Item) from the underlying file at the current @noAutoLink(position).} 147 | function ReadSingle(var Item: Single): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 148 | {Writes a single instance of Single from @code(Item) to the underlying file at the current @noAutoLink(position), possibly overwriting existing data.} 149 | function WriteSingle(const Item: Single): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 150 | {Writes a single instance of Single from @code(Item) to the underlying file at the last @noAutoLink(position), behind any existing data.} 151 | function AppendSingle(const Item: Single): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 152 | {Reads a single instance of Double into @code(Item) from the underlying file at the current @noAutoLink(position).} 153 | function ReadDouble(var Item: Double): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 154 | {Writes a single instance of Double from @code(Item) to the underlying file at the current @noAutoLink(position), possibly overwriting existing data.} 155 | function WriteDouble(const Item: Double): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 156 | {Writes a single instance of Double from @code(Item) to the underlying file at the last @noAutoLink(position), behind any existing data.} 157 | function AppendDouble(const Item: Double): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 158 | {Reads a single instance of Extended into @code(Item) from the underlying file at the current @noAutoLink(position).} 159 | function ReadExtended(var Item: Extended): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 160 | {Writes a single instance of Extended from @code(Item) to the underlying file at the current @noAutoLink(position), possibly overwriting existing data.} 161 | function WriteExtended(const Item: Extended): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 162 | {Writes a single instance of Extended from @code(Item) to the underlying file at the last @noAutoLink(position), behind any existing data.} 163 | function AppendExtended(const Item: Extended): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 164 | {Reads a single instance of Currency into @code(Item) from the underlying file at the current @noAutoLink(position).} 165 | function ReadCurrency(var Item: Currency): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 166 | {Writes a single instance of Currency from @code(Item) to the underlying file at the current @noAutoLink(position), possibly overwriting existing data.} 167 | function WriteCurrency(const Item: Currency): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 168 | {Writes a single instance of Currency from @code(Item) to the underlying file at the last @noAutoLink(position), behind any existing data.} 169 | function AppendCurrency(const Item: Currency): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 170 | {Reads a single instance of TDateTime into @code(Item) from the underlying file at the current @noAutoLink(position).} 171 | function ReadDateTime(var Item: TDateTime): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 172 | {Writes a single instance of TDateTime from @code(Item) to the underlying file at the current @noAutoLink(position), possibly overwriting existing data.} 173 | function WriteDateTime(const Item: TDateTime): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 174 | {Writes a single instance of TDateTime from @code(Item) to the underlying file at the last @noAutoLink(position), behind any existing data.} 175 | function AppendDateTime(const Item: TDateTime): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 176 | {Reads a single instance of AnsiChar into @code(Item) from the underlying file at the current @noAutoLink(position).} 177 | function ReadAnsiChar(var Item: AnsiChar): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 178 | {Writes a single instance of AnsiChar from @code(Item) to the underlying file at the current @noAutoLink(position), possibly overwriting existing data.} 179 | function WriteAnsiChar(const Item: AnsiChar): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 180 | {Writes a single instance of AnsiChar from @code(Item) to the underlying file at the last @noAutoLink(position), behind any existing data.} 181 | function AppendAnsiChar(const Item: AnsiChar): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 182 | {Reads a single instance of WideChar into @code(Item) from the underlying file at the current @noAutoLink(position).} 183 | function ReadWideChar(var Item: WideChar): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 184 | {Writes a single instance of WideChar from @code(Item) to the underlying file at the current @noAutoLink(position), possibly overwriting existing data.} 185 | function WriteWideChar(const Item: WideChar): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 186 | {Writes a single instance of WideChar from @code(Item) to the underlying file at the last @noAutoLink(position), behind any existing data.} 187 | function AppendWideChar(const Item: WideChar): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 188 | {Reads a single instance of UnicodeChar into @code(Item) from the underlying file at the current @noAutoLink(position).} 189 | function ReadUnicodeChar(var Item: UnicodeChar): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 190 | {Writes a single instance of UnicodeChar from @code(Item) to the underlying file at the current @noAutoLink(position), possibly overwriting existing data.} 191 | function WriteUnicodeChar(const Item: UnicodeChar): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 192 | {Writes a single instance of UnicodeChar from @code(Item) to the underlying file at the last @noAutoLink(position), behind any existing data.} 193 | function AppendUnicodeChar(const Item: UnicodeChar): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 194 | {Reads @code(NumChars) worth of AnsiChars into @code(Item) from the underlying file at the current @noAutoLink(position).} 195 | function ReadShortString(var Item: ShortString; const NumChars: SizeInt): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 196 | {Writes a single instance of ShortString from @code(Item) to the underlying file at the current @noAutoLink(position), possibly overwriting existing data.} 197 | function WriteShortString(const Item: ShortString): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 198 | {Writes a single instance of ShortString from @code(Item) to the underlying file at the last @noAutoLink(position), behind any existing data.} 199 | function AppendShortString(const Item: ShortString): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 200 | {Reads @code(NumChars) worth of AnsiChars into @code(Item) from the underlying file at the current @noAutoLink(position).} 201 | function ReadAnsiString(var Item: AnsiString; const NumChars: SizeInt): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 202 | {Writes a single instance of AnsiString from @code(Item) to the underlying file at the current @noAutoLink(position), possibly overwriting existing data.} 203 | function WriteAnsiString(const Item: AnsiString): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 204 | {Writes a single instance of AnsiString from @code(Item) to the underlying file at the last @noAutoLink(position), behind any existing data.} 205 | function AppendAnsiString(const Item: AnsiString): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 206 | {Reads @code(NumChars) worth of WideChars into @code(Item) from the underlying file at the current @noAutoLink(position).} 207 | function ReadWideString(var Item: WideString; const NumChars: SizeInt): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 208 | {Writes a single instance of WideString from @code(Item) to the underlying file at the current @noAutoLink(position), possibly overwriting existing data.} 209 | function WriteWideString(const Item: WideString): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 210 | {Writes a single instance of WideString from @code(Item) to the underlying file at the last @noAutoLink(position), behind any existing data.} 211 | function AppendWideString(const Item: WideString): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 212 | {Reads @code(NumChars) worth of UnicodeChars into @code(Item) from the underlying file at the current @noAutoLink(position).} 213 | function ReadUnicodeString(var Item: UnicodeString; const NumChars: SizeInt): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 214 | {Writes a single instance of UnicodeString from @code(Item) to the underlying file at the current @noAutoLink(position), possibly overwriting existing data.} 215 | function WriteUnicodeString(const Item: UnicodeString): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 216 | {Writes a single instance of UnicodeString from @code(Item) to the underlying file at the last @noAutoLink(position), behind any existing data.} 217 | function AppendUnicodeString(const Item: UnicodeString): PLightFileStream; {$IFNDEF DEBUG}inline;{$ENDIF} 218 | {Indicates directly whether or not the underlying file is open.} 219 | property IsOpen: Boolean read FOpen; 220 | end; 221 | 222 | implementation 223 | 224 | class function TLightFileStream.Create(const FileName: PChar): TLightFileStream; 225 | begin 226 | with Result do begin 227 | FFileName := FileName; 228 | FHandle := FileCreate(FFileName); 229 | FOpen := (FHandle <> THandle(-1)); 230 | FState := fsWriting; 231 | end; 232 | end; 233 | 234 | class function TLightFileStream.Open(const FileName: PChar; const InitialState: TFileState): TLightFileStream; 235 | begin 236 | with Result do begin 237 | FFileName := FileName; 238 | case InitialState of 239 | fsReading: FHandle := FileOpen(FFileName, fmOpenRead); 240 | fsWriting: FHandle := FileOpen(FFileName, fmOpenWrite); 241 | end; 242 | FOpen := (FHandle <> THandle(-1)); 243 | FState := InitialState; 244 | end; 245 | end; 246 | 247 | procedure TLightFileStream.Close; 248 | begin 249 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 250 | if not FOpen then Exit(); 251 | {$ENDIF} 252 | FileClose(FHandle); 253 | end; 254 | 255 | function TLightFileStream.ChangeFileStateTo(const State: TFileState): PLightFileStream; 256 | begin 257 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 258 | if (not FOpen) or (State = FState) then Exit(@Self); 259 | {$ENDIF} 260 | FileClose(FHandle); 261 | case State of 262 | fsReading: FHandle := FileOpen(FFileName, fmOpenRead); 263 | fsWriting: FHandle := FileOpen(FFileName, fmOpenWrite); 264 | end; 265 | FOpen := (FHandle <> THandle(-1)); 266 | FState := State; 267 | Result := @Self; 268 | end; 269 | 270 | function TLightFileStream.SeekFromBeginning(const ToPosition: SizeInt): PLightFileStream; 271 | begin 272 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 273 | if not FOpen then Exit(@Self); 274 | {$ENDIF} 275 | FileSeek(FHandle, ToPosition, fsFromBeginning); 276 | Result := @Self; 277 | end; 278 | 279 | function TLightFileStream.SeekFromCurrent(const ToPosition: SizeInt): PLightFileStream; 280 | begin 281 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 282 | if not FOpen then Exit(@Self); 283 | {$ENDIF} 284 | FileSeek(FHandle, ToPosition, fsFromCurrent); 285 | Result := @Self; 286 | end; 287 | 288 | function TLightFileStream.SeekFromEnd(const ToPosition: SizeInt): PLightFileStream; 289 | begin 290 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 291 | if not FOpen then Exit(@Self); 292 | {$ENDIF} 293 | FileSeek(FHandle, ToPosition, fsFromEnd); 294 | Result := @Self; 295 | end; 296 | 297 | function TLightFileStream.GetSize(out TheSize: SizeInt): PLightFileStream; 298 | var CurrentPosition: SizeInt; 299 | begin 300 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 301 | if not FOpen then Exit(@Self); 302 | {$ENDIF} 303 | CurrentPosition := FileSeek(FHandle, 0, fsFromCurrent); 304 | TheSize := FileSeek(FHandle, 0, fsFromEnd); 305 | FileSeek(FHandle, CurrentPosition, fsFromBeginning); 306 | Result := @Self; 307 | end; 308 | 309 | function TLightFileStream.PutSize: SizeInt; 310 | begin 311 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 312 | if not FOpen then Exit(0); 313 | {$ENDIF} 314 | GetSize(Result); 315 | end; 316 | 317 | function TLightFileStream.LogSize: PLightFileStream; 318 | var CurrentSize: SizeInt = 0; 319 | begin 320 | if not IsConsole then Exit(@Self); 321 | GetSize(CurrentSize); 322 | WriteLn('Size of TLightFileStream instance with file handle ', FHandle, ': ', CurrentSize); 323 | Result := @Self; 324 | end; 325 | 326 | function TLightFileStream.GetPosition(out ThePosition: SizeInt): PLightFileStream; 327 | begin 328 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 329 | if not FOpen then Exit(@Self); 330 | {$ENDIF} 331 | ThePosition := FileSeek(FHandle, 0, fsFromCurrent); 332 | Result := @Self; 333 | end; 334 | 335 | function TLightFileStream.PutPosition: SizeInt; 336 | begin 337 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 338 | if not FOpen then Exit(0); 339 | {$ENDIF} 340 | GetPosition(Result); 341 | end; 342 | 343 | function TLightFileStream.LogPosition: PLightFileStream; 344 | var CurrentPosition: SizeInt = 0; 345 | begin 346 | if not IsConsole then Exit(@Self); 347 | GetPosition(CurrentPosition); 348 | WriteLn('Position of TLightFileStream instance with file handle ', FHandle, ': ', CurrentPosition); 349 | Result := @Self; 350 | end; 351 | 352 | function TLightFileStream.Truncate: PLightFileStream; 353 | var CurrentSize: SizeInt; 354 | begin 355 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 356 | if not FOpen then Exit(@Self); 357 | {$ENDIF} 358 | GetSize(CurrentSize); 359 | FileTruncate(FHandle, CurrentSize - (CurrentSize - FileSeek(FHandle, 0, fsFromCurrent))); 360 | Result := @Self; 361 | end; 362 | 363 | function TLightFileStream.ReadType<T>(var Item: T): PLightFileStream; 364 | begin 365 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 366 | if (not FOpen) or (FState <> fsReading) then Exit(@Self); 367 | {$ENDIF} 368 | FileRead(FHandle, Item, SizeOf(T)); 369 | Result := @Self; 370 | end; 371 | 372 | function TLightFileStream.WriteType<T>(constref Item: T): PLightFileStream; 373 | begin 374 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 375 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 376 | {$ENDIF} 377 | FileWrite(FHandle, Item, SizeOf(T)); 378 | Result := @Self; 379 | end; 380 | 381 | function TLightFileStream.AppendType<T>(constref Item: T): PLightFileStream; 382 | begin 383 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 384 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 385 | {$ENDIF} 386 | FileSeek(FHandle, 0, fsFromEnd); 387 | FileWrite(FHandle, Item, SizeOf(T)); 388 | Result := @Self; 389 | end; 390 | 391 | function TLightFileStream.FillWith<T>(constref Value: T; const NumInstances: SizeUInt): PLightFileStream; 392 | var I: SizeUInt; 393 | begin 394 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 395 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 396 | {$ENDIF} 397 | for I := 1 to NumInstances do WriteType<T>(Value); 398 | Result := @Self; 399 | end; 400 | 401 | function TLightFileStream.ReadTypedBuffer<T>(var Buffer: T; const ItemCount: SizeInt): PLightFileStream; 402 | begin 403 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 404 | if (not FOpen) or (FState <> fsReading) then Exit(@Self); 405 | {$ENDIF} 406 | FileRead(FHandle, Buffer, SizeOf(T) * ItemCount); 407 | Result := @Self; 408 | end; 409 | 410 | function TLightFileStream.WriteTypedBuffer<T>(constref Buffer: T; const ItemCount: SizeInt): PLightFileStream; 411 | begin 412 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 413 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 414 | {$ENDIF} 415 | FileWrite(FHandle, Buffer, SizeOf(T) * ItemCount); 416 | Result := @Self; 417 | end; 418 | 419 | function TLightFileStream.AppendTypedBuffer<T>(constref Buffer: T; const ItemCount: SizeInt): PLightFileStream; 420 | begin 421 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 422 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 423 | {$ENDIF} 424 | FileSeek(FHandle, 0, fsFromEnd); 425 | FileWrite(FHandle, Buffer, SizeOf(T) * ItemCount); 426 | Result := @Self; 427 | end; 428 | 429 | function TLightFileStream.ReadPointerBuffer(const Buffer: Pointer; const NumBytesToRead: SizeInt): PLightFileStream; 430 | begin 431 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 432 | if (not FOpen) or (FState <> fsReading) then Exit(@Self); 433 | {$ENDIF} 434 | FileRead(FHandle, Buffer^, NumBytesToRead); 435 | Result := @Self; 436 | end; 437 | 438 | function TLightFileStream.WritePointerBuffer(const Buffer: Pointer; const NumBytesToWrite: SizeInt): PLightFileStream; 439 | begin 440 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 441 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 442 | {$ENDIF} 443 | FileWrite(FHandle, Buffer^, NumBytesToWrite); 444 | Result := @Self; 445 | end; 446 | 447 | function TLightFileStream.AppendPointerBuffer(const Buffer: Pointer; const NumBytesToWrite: SizeInt): PLightFileStream; 448 | begin 449 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 450 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 451 | {$ENDIF} 452 | FileSeek(FHandle, 0, fsFromEnd); 453 | FileWrite(FHandle, Buffer^, NumBytesToWrite); 454 | Result := @Self; 455 | end; 456 | 457 | function TLightFileStream.ReadByte(var Item: Byte): PLightFileStream; 458 | begin 459 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 460 | if (not FOpen) or (FState <> fsReading) then Exit(@Self); 461 | {$ENDIF} 462 | FileRead(FHandle, Item, SizeOf(Byte)); 463 | Result := @Self; 464 | end; 465 | 466 | function TLightFileStream.WriteByte(const Item: Byte): PLightFileStream; 467 | begin 468 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 469 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 470 | {$ENDIF} 471 | FileWrite(FHandle, Item, SizeOf(Byte)); 472 | Result := @Self; 473 | end; 474 | 475 | function TLightFileStream.AppendByte(const Item: Byte): PLightFileStream; 476 | begin 477 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 478 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 479 | {$ENDIF} 480 | FileSeek(FHandle, 0, fsFromEnd); 481 | FileWrite(FHandle, Item, SizeOf(Byte)); 482 | Result := @Self; 483 | end; 484 | 485 | function TLightFileStream.ReadWord(var Item: Word): PLightFileStream; 486 | begin 487 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 488 | if (not FOpen) or (FState <> fsReading) then Exit(@Self); 489 | {$ENDIF} 490 | FileRead(FHandle, Item, SizeOf(Word)); 491 | Result := @Self; 492 | end; 493 | 494 | function TLightFileStream.WriteWord(const Item: Word): PLightFileStream; 495 | begin 496 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 497 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 498 | {$ENDIF} 499 | FileWrite(FHandle, Item, SizeOf(Word)); 500 | Result := @Self; 501 | end; 502 | 503 | function TLightFileStream.AppendWord(const Item: Word): PLightFileStream; 504 | begin 505 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 506 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 507 | {$ENDIF} 508 | FileSeek(FHandle, 0, fsFromEnd); 509 | FileWrite(FHandle, Item, SizeOf(Word)); 510 | Result := @Self; 511 | end; 512 | 513 | function TLightFileStream.ReadLongWord(var Item: LongWord): PLightFileStream; 514 | begin 515 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 516 | if (not FOpen) or (FState <> fsReading) then Exit(@Self); 517 | {$ENDIF} 518 | FileRead(FHandle, Item, SizeOf(LongWord)); 519 | Result := @Self; 520 | end; 521 | 522 | function TLightFileStream.WriteLongWord(const Item: LongWord): PLightFileStream; 523 | begin 524 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 525 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 526 | {$ENDIF} 527 | FileWrite(FHandle, Item, SizeOf(LongWord)); 528 | Result := @Self; 529 | end; 530 | 531 | function TLightFileStream.AppendLongWord(const Item: LongWord): PLightFileStream; 532 | begin 533 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 534 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 535 | {$ENDIF} 536 | FileSeek(FHandle, 0, fsFromEnd); 537 | FileWrite(FHandle, Item, SizeOf(LongWord)); 538 | Result := @Self; 539 | end; 540 | 541 | function TLightFileStream.ReadQWord(var Item: QWord): PLightFileStream; 542 | begin 543 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 544 | if (not FOpen) or (FState <> fsReading) then Exit(@Self); 545 | {$ENDIF} 546 | FileRead(FHandle, Item, SizeOf(QWord)); 547 | Result := @Self; 548 | end; 549 | 550 | function TLightFileStream.WriteQWord(const Item: QWord): PLightFileStream; 551 | begin 552 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 553 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 554 | {$ENDIF} 555 | FileWrite(FHandle, Item, SizeOf(QWord)); 556 | Result := @Self; 557 | end; 558 | 559 | function TLightFileStream.AppendQWord(const Item: QWord): PLightFileStream; 560 | begin 561 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 562 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 563 | {$ENDIF} 564 | FileSeek(FHandle, 0, fsFromEnd); 565 | FileWrite(FHandle, Item, SizeOf(QWord)); 566 | Result := @Self; 567 | end; 568 | 569 | function TLightFileStream.ReadShortInt(var Item: ShortInt): PLightFileStream; 570 | begin 571 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 572 | if (not FOpen) or (FState <> fsReading) then Exit(@Self); 573 | {$ENDIF} 574 | FileRead(FHandle, Item, SizeOf(ShortInt)); 575 | Result := @Self; 576 | end; 577 | 578 | function TLightFileStream.WriteShortInt(const Item: ShortInt): PLightFileStream; 579 | begin 580 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 581 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 582 | {$ENDIF} 583 | FileWrite(FHandle, Item, SizeOf(ShortInt)); 584 | Result := @Self; 585 | end; 586 | 587 | function TLightFileStream.AppendShortInt(const Item: ShortInt): PLightFileStream; 588 | begin 589 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 590 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 591 | {$ENDIF} 592 | FileSeek(FHandle, 0, fsFromEnd); 593 | FileWrite(FHandle, Item, SizeOf(ShortInt)); 594 | Result := @Self; 595 | end; 596 | 597 | function TLightFileStream.ReadSmallInt(var Item: SmallInt): PLightFileStream; 598 | begin 599 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 600 | if (not FOpen) or (FState <> fsReading) then Exit(@Self); 601 | {$ENDIF} 602 | FileRead(FHandle, Item, SizeOf(SmallInt)); 603 | Result := @Self; 604 | end; 605 | 606 | function TLightFileStream.WriteSmallInt(const Item: SmallInt): PLightFileStream; 607 | begin 608 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 609 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 610 | {$ENDIF} 611 | FileWrite(FHandle, Item, SizeOf(SmallInt)); 612 | Result := @Self; 613 | end; 614 | 615 | function TLightFileStream.AppendSmallInt(const Item: SmallInt): PLightFileStream; 616 | begin 617 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 618 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 619 | {$ENDIF} 620 | FileSeek(FHandle, 0, fsFromEnd); 621 | FileWrite(FHandle, Item, SizeOf(SmallInt)); 622 | Result := @Self; 623 | end; 624 | 625 | function TLightFileStream.ReadLongInt(var Item: LongInt): PLightFileStream; 626 | begin 627 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 628 | if (not FOpen) or (FState <> fsReading) then Exit(@Self); 629 | {$ENDIF} 630 | FileRead(FHandle, Item, SizeOf(LongInt)); 631 | Result := @Self; 632 | end; 633 | 634 | function TLightFileStream.WriteLongInt(const Item: LongInt): PLightFileStream; 635 | begin 636 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 637 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 638 | {$ENDIF} 639 | FileWrite(FHandle, Item, SizeOf(LongInt)); 640 | Result := @Self; 641 | end; 642 | 643 | function TLightFileStream.AppendLongInt(const Item: LongInt): PLightFileStream; 644 | begin 645 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 646 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 647 | {$ENDIF} 648 | FileSeek(FHandle, 0, fsFromEnd); 649 | FileWrite(FHandle, Item, SizeOf(LongInt)); 650 | Result := @Self; 651 | end; 652 | 653 | function TLightFileStream.ReadInt64(var Item: Int64): PLightFileStream; 654 | begin 655 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 656 | if (not FOpen) or (FState <> fsReading) then Exit(@Self); 657 | {$ENDIF} 658 | FileRead(FHandle, Item, SizeOf(Int64)); 659 | Result := @Self; 660 | end; 661 | 662 | function TLightFileStream.WriteInt64(const Item: Int64): PLightFileStream; 663 | begin 664 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 665 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 666 | {$ENDIF} 667 | FileWrite(FHandle, Item, SizeOf(Int64)); 668 | Result := @Self; 669 | end; 670 | 671 | function TLightFileStream.AppendInt64(const Item: Int64): PLightFileStream; 672 | begin 673 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 674 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 675 | {$ENDIF} 676 | FileSeek(FHandle, 0, fsFromEnd); 677 | FileWrite(FHandle, Item, SizeOf(Int64)); 678 | Result := @Self; 679 | end; 680 | 681 | function TLightFileStream.ReadSingle(var Item: Single): PLightFileStream; 682 | begin 683 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 684 | if (not FOpen) or (FState <> fsReading) then Exit(@Self); 685 | {$ENDIF} 686 | FileRead(FHandle, Item, SizeOf(Single)); 687 | Result := @Self; 688 | end; 689 | 690 | function TLightFileStream.WriteSingle(const Item: Single): PLightFileStream; 691 | begin 692 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 693 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 694 | {$ENDIF} 695 | FileWrite(FHandle, Item, SizeOf(Single)); 696 | Result := @Self; 697 | end; 698 | 699 | function TLightFileStream.AppendSingle(const Item: Single): PLightFileStream; 700 | begin 701 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 702 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 703 | {$ENDIF} 704 | FileSeek(FHandle, 0, fsFromEnd); 705 | FileWrite(FHandle, Item, SizeOf(Single)); 706 | Result := @Self; 707 | end; 708 | 709 | function TLightFileStream.ReadDouble(var Item: Double): PLightFileStream; 710 | begin 711 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 712 | if (not FOpen) or (FState <> fsReading) then Exit(@Self); 713 | {$ENDIF} 714 | FileRead(FHandle, Item, SizeOf(Double)); 715 | Result := @Self; 716 | end; 717 | 718 | function TLightFileStream.WriteDouble(const Item: Double): PLightFileStream; 719 | begin 720 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 721 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 722 | {$ENDIF} 723 | FileWrite(FHandle, Item, SizeOf(Double)); 724 | Result := @Self; 725 | end; 726 | 727 | function TLightFileStream.AppendDouble(const Item: Double): PLightFileStream; 728 | begin 729 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 730 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 731 | {$ENDIF} 732 | FileSeek(FHandle, 0, fsFromEnd); 733 | FileWrite(FHandle, Item, SizeOf(Double)); 734 | Result := @Self; 735 | end; 736 | 737 | function TLightFileStream.ReadExtended(var Item: Extended): PLightFileStream; 738 | begin 739 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 740 | if (not FOpen) or (FState <> fsReading) then Exit(@Self); 741 | {$ENDIF} 742 | FileRead(FHandle, Item, SizeOf(Extended)); 743 | Result := @Self; 744 | end; 745 | 746 | function TLightFileStream.WriteExtended(const Item: Extended): PLightFileStream; 747 | begin 748 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 749 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 750 | {$ENDIF} 751 | FileWrite(FHandle, Item, SizeOf(Extended)); 752 | Result := @Self; 753 | end; 754 | 755 | function TLightFileStream.AppendExtended(const Item: Extended): PLightFileStream; 756 | begin 757 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 758 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 759 | {$ENDIF} 760 | FileSeek(FHandle, 0, fsFromEnd); 761 | FileWrite(FHandle, Item, SizeOf(Extended)); 762 | Result := @Self; 763 | end; 764 | 765 | function TLightFileStream.ReadCurrency(var Item: Currency): PLightFileStream; 766 | begin 767 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 768 | if (not FOpen) or (FState <> fsReading) then Exit(@Self); 769 | {$ENDIF} 770 | FileRead(FHandle, Item, SizeOf(Currency)); 771 | Result := @Self; 772 | end; 773 | 774 | function TLightFileStream.WriteCurrency(const Item: Currency): PLightFileStream; 775 | begin 776 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 777 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 778 | {$ENDIF} 779 | FileWrite(FHandle, Item, SizeOf(Currency)); 780 | Result := @Self; 781 | end; 782 | 783 | function TLightFileStream.AppendCurrency(const Item: Currency): PLightFileStream; 784 | begin 785 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 786 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 787 | {$ENDIF} 788 | FileSeek(FHandle, 0, fsFromEnd); 789 | FileWrite(FHandle, Item, SizeOf(Currency)); 790 | Result := @Self; 791 | end; 792 | 793 | function TLightFileStream.ReadDateTime(var Item: TDateTime): PLightFileStream; 794 | begin 795 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 796 | if (not FOpen) or (FState <> fsReading) then Exit(@Self); 797 | {$ENDIF} 798 | FileRead(FHandle, Item, SizeOf(TDateTime)); 799 | Result := @Self; 800 | end; 801 | 802 | function TLightFileStream.WriteDateTime(const Item: TDateTime): PLightFileStream; 803 | begin 804 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 805 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 806 | {$ENDIF} 807 | FileWrite(FHandle, Item, SizeOf(TDateTime)); 808 | Result := @Self; 809 | end; 810 | 811 | function TLightFileStream.AppendDateTime(const Item: TDateTime): PLightFileStream; 812 | begin 813 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 814 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 815 | {$ENDIF} 816 | FileSeek(FHandle, 0, fsFromEnd); 817 | FileWrite(FHandle, Item, SizeOf(TDateTime)); 818 | Result := @Self; 819 | end; 820 | 821 | function TLightFileStream.ReadAnsiChar(var Item: AnsiChar): PLightFileStream; 822 | begin 823 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 824 | if (not FOpen) or (FState <> fsReading) then Exit(@Self); 825 | {$ENDIF} 826 | FileRead(FHandle, Item, SizeOf(AnsiChar)); 827 | Result := @Self; 828 | end; 829 | 830 | function TLightFileStream.WriteAnsiChar(const Item: AnsiChar): PLightFileStream; 831 | begin 832 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 833 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 834 | {$ENDIF} 835 | FileWrite(FHandle, Item, SizeOf(AnsiChar)); 836 | Result := @Self; 837 | end; 838 | 839 | function TLightFileStream.AppendAnsiChar(const Item: AnsiChar): PLightFileStream; 840 | begin 841 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 842 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 843 | {$ENDIF} 844 | FileSeek(FHandle, 0, fsFromEnd); 845 | FileWrite(FHandle, Item, SizeOf(AnsiChar)); 846 | Result := @Self; 847 | end; 848 | 849 | function TLightFileStream.ReadWideChar(var Item: WideChar): PLightFileStream; 850 | begin 851 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 852 | if (not FOpen) or (FState <> fsReading) then Exit(@Self); 853 | {$ENDIF} 854 | FileRead(FHandle, Item, SizeOf(WideChar)); 855 | Result := @Self; 856 | end; 857 | 858 | function TLightFileStream.WriteWideChar(const Item: WideChar): PLightFileStream; 859 | begin 860 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 861 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 862 | {$ENDIF} 863 | FileWrite(FHandle, Item, SizeOf(WideChar)); 864 | Result := @Self; 865 | end; 866 | 867 | function TLightFileStream.AppendWideChar(const Item: WideChar): PLightFileStream; 868 | begin 869 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 870 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 871 | {$ENDIF} 872 | FileSeek(FHandle, 0, fsFromEnd); 873 | FileWrite(FHandle, Item, SizeOf(WideChar)); 874 | Result := @Self; 875 | end; 876 | 877 | function TLightFileStream.ReadUnicodeChar(var Item: UnicodeChar): PLightFileStream; 878 | begin 879 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 880 | if (not FOpen) or (FState <> fsReading) then Exit(@Self); 881 | {$ENDIF} 882 | FileRead(FHandle, Item, SizeOf(UnicodeChar)); 883 | Result := @Self; 884 | end; 885 | 886 | function TLightFileStream.WriteUnicodeChar(const Item: UnicodeChar): PLightFileStream; 887 | begin 888 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 889 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 890 | {$ENDIF} 891 | FileWrite(FHandle, Item, SizeOf(UnicodeChar)); 892 | Result := @Self; 893 | end; 894 | 895 | function TLightFileStream.AppendUnicodeChar(const Item: UnicodeChar): PLightFileStream; 896 | begin 897 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 898 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 899 | {$ENDIF} 900 | FileSeek(FHandle, 0, fsFromEnd); 901 | FileWrite(FHandle, Item, SizeOf(UnicodeChar)); 902 | Result := @Self; 903 | end; 904 | 905 | function TLightFileStream.ReadShortString(var Item: ShortString; const NumChars: SizeInt): PLightFileStream; 906 | begin 907 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 908 | if (not FOpen) or (FState <> fsReading) then Exit(@Self); 909 | {$ENDIF} 910 | FileRead(FHandle, Item[1], NumChars); 911 | Result := @Self; 912 | end; 913 | 914 | function TLightFileStream.WriteShortString(const Item: ShortString): PLightFileStream; 915 | begin 916 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 917 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 918 | {$ENDIF} 919 | FileWrite(FHandle, Item[1], Length(Item)); 920 | Result := @Self; 921 | end; 922 | 923 | function TLightFileStream.AppendShortString(const Item: ShortString): PLightFileStream; 924 | begin 925 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 926 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 927 | {$ENDIF} 928 | FileSeek(FHandle, 0, fsFromEnd); 929 | FileWrite(FHandle, Item[1], Length(Item)); 930 | Result := @Self; 931 | end; 932 | 933 | function TLightFileStream.ReadAnsiString(var Item: AnsiString; const NumChars: SizeInt): PLightFileStream; 934 | begin 935 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 936 | if (not FOpen) or (FState <> fsReading) then Exit(@Self); 937 | {$ENDIF} 938 | FileRead(FHandle, Item[1], NumChars); 939 | Result := @Self; 940 | end; 941 | 942 | function TLightFileStream.WriteAnsiString(const Item: AnsiString): PLightFileStream; 943 | begin 944 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 945 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 946 | {$ENDIF} 947 | FileWrite(FHandle, Item[1], Length(Item)); 948 | Result := @Self; 949 | end; 950 | 951 | function TLightFileStream.AppendAnsiString(const Item: AnsiString): PLightFileStream; 952 | begin 953 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 954 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 955 | {$ENDIF} 956 | FileSeek(FHandle, 0, fsFromEnd); 957 | FileWrite(FHandle, Item[1], Length(Item)); 958 | Result := @Self; 959 | end; 960 | 961 | function TLightFileStream.ReadWideString(var Item: WideString; const NumChars: SizeInt): PLightFileStream; 962 | begin 963 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 964 | if (not FOpen) or (FState <> fsReading) then Exit(@Self); 965 | {$ENDIF} 966 | FileRead(FHandle, Item[1], SizeOf(WideChar) * NumChars); 967 | Result := @Self; 968 | end; 969 | 970 | function TLightFileStream.WriteWideString(const Item: WideString): PLightFileStream; 971 | begin 972 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 973 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 974 | {$ENDIF} 975 | FileWrite(FHandle, Item[1], TEncoding.Unicode.GetByteCount(Item)); 976 | Result := @Self; 977 | end; 978 | 979 | function TLightFileStream.AppendWideString(const Item: WideString): PLightFileStream; 980 | begin 981 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 982 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 983 | {$ENDIF} 984 | FileSeek(FHandle, 0, fsFromEnd); 985 | FileWrite(FHandle, Item[1], TEncoding.Unicode.GetByteCount(Item)); 986 | Result := @Self; 987 | end; 988 | 989 | function TLightFileStream.ReadUnicodeString(var Item: UnicodeString; const NumChars: SizeInt): PLightFileStream; 990 | begin 991 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 992 | if (not FOpen) or (FState <> fsReading) then Exit(@Self); 993 | {$ENDIF} 994 | FileRead(FHandle, Item[1], SizeOf(UnicodeChar) * NumChars); 995 | Result := @Self; 996 | end; 997 | 998 | function TLightFileStream.WriteUnicodeString(const Item: UnicodeString): PLightFileStream; 999 | begin 1000 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 1001 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 1002 | {$ENDIF} 1003 | FileWrite(FHandle, Item[1], TEncoding.Unicode.GetByteCount(Item)); 1004 | Result := @Self; 1005 | end; 1006 | 1007 | function TLightFileStream.AppendUnicodeString(const Item: UnicodeString): PLightFileStream; 1008 | begin 1009 | {$IFNDEF LIGHTFILESTREAM_NOCHECKS} 1010 | if (not FOpen) or (FState <> fsWriting) then Exit(@Self); 1011 | {$ENDIF} 1012 | FileSeek(FHandle, 0, fsFromEnd); 1013 | FileWrite(FHandle, Item[1], TEncoding.Unicode.GetByteCount(Item)); 1014 | Result := @Self; 1015 | end; 1016 | 1017 | end. 1018 | -------------------------------------------------------------------------------- /update_LazLightFileStream.json: -------------------------------------------------------------------------------- 1 | { 2 | "UpdatePackageData" : { 3 | "DisableInOPM" : false, 4 | "DownloadZipURL" : "https://github.com/Akira13641/TLightFileStream/releases/download/1.2.1/LazLightFileStream.zip", 5 | "Name" : "LazLightFileStream.zip" 6 | }, 7 | "UpdatePackageFiles" : [ 8 | { 9 | "ForceNotify" : true, 10 | "InternalVersion" : 4, 11 | "Name" : "LazLightFileStream.lpk", 12 | "Version" : "1.2.1.0" 13 | } 14 | ] 15 | } 16 | --------------------------------------------------------------------------------