Преглед на файлове

A few extensions for tentryfile needed for package files

entfile.pas, tentryfile:
  + new property position to retrieve/control the position of the underlying stream (works also with tempclose()/tempopen())
  + new method substream() to retrieve a stream that goes from the specified offset with the specified length (-1 create a stream that is extendable, aka for writing)
  + new property stream to get the underlying stream directly; be careful when using this!

git-svn-id: branches/svenbarth/packages@32304 -
svenbarth преди 9 години
родител
ревизия
731fe29b3e
променени са 1 файла, в които са добавени 38 реда и са изтрити 0 реда
  1. 38 0
      compiler/entfile.pas

+ 38 - 0
compiler/entfile.pas

@@ -198,6 +198,9 @@ interface
     pentryheader=^tentryheader;
 
     tentryfile=class
+    private
+      function getposition:longint;
+      procedure setposition(value:longint);
     protected
       buf      : pchar;
       bufstart,
@@ -236,6 +239,11 @@ interface
       procedure flush;
       procedure closefile;virtual;
       procedure newentry;
+      property position:longint read getposition write setposition;
+      { Warning: don't keep the stream open during a tempclose! }
+      function substream(ofs,len:longint):TCStream;
+      { Warning: don't use the put* or write* functions anymore when writing through this }
+      property stream:TCStream read f;
     {read}
       function  openfile:boolean;
       function  openstream(strm:TCStream):boolean;
@@ -372,6 +380,36 @@ implementation
     end;
 
 
+  procedure tentryfile.setposition(value:longint);
+    begin
+      if assigned(f) then
+        f.Position:=value
+      else
+        if tempclosed then
+          closepos:=value;
+    end;
+
+
+  function tentryfile.getposition:longint;
+    begin
+      if assigned(f) then
+        result:=f.Position
+      else
+        if tempclosed then
+          result:=closepos
+        else
+          result:=0;
+    end;
+
+
+  function tentryfile.substream(ofs,len:longint):TCStream;
+    begin
+      result:=nil;
+      if assigned(f) then
+        result:=TCRangeStream.Create(f,ofs,len);
+    end;
+
+
   {*****************************************************************************
                                   tentryfile Reading
   *****************************************************************************}