Recent

Author Topic: About the following Object pascal component...  (Read 2229 times)

aminer

  • Hero Member
  • *****
  • Posts: 956
About the following Object pascal component...
« on: February 09, 2013, 09:19:09 pm »

Hello,

We have to be carrefull about Object pascal ccomponents,
for exemple look at the following source code called zipfile:

https://modelbuilder.svn.sourceforge.net/svnroot/modelbuilder/src/trunk/mcl/zipfile/zipfile.pas

First:

In the AppendStream() he is compressing directly
to the memory and that's not good, he must copy the data directly
to the filestream, that's a more optimized method to not use a lot
of memory.


Second:


As you will notice this zipfile component is not Fault tolerant to power failures etc so what will happen if there is a power failure
and the zip file is corrupt ? your zipfile and data will be lost, and
that's not good, so he must redesign his componenet to be fault tolerant..


Thank you,
Amine Moulay Ramdane.




aminer

  • Hero Member
  • *****
  • Posts: 956
Re: About the following Object pascal component...
« Reply #1 on: February 09, 2013, 09:29:06 pm »


Hello again,

Look at the LoadFromStream method of my ParallelVarFiler source code here: http://pages.videotron.com/aminer/

Here it is:

==

function TParallelVarFiler.LoadFromStream(Stream : TStream):boolean;
var
  VR : PScwVarRecord;
  str:string;
  a:integer;
  delbit:byte;
  pos:integer;
Begin
result:=true;
  Clear;
  Try
    While Stream.Position < Stream.Size do
    Begin
      pos:=stream.position;
      New(VR);
      Stream.Read(delbit, SizeOf(byte)); 
      Stream.Read(a, SizeOf(integer));  // Name length
      SetLength(str, a);             // Get memory to the Name
      Stream.Read(Pointer(str)^, a); // Name
      Stream.Read(VR^.T, SizeOf(VR^.T));    // Variable Type
      if (Stream.size-Stream.position)<sizeof(VR^.SL)
       then
         begin
          dispose(VR);
          setlength(str,0);
          Stream.size:=pos;
          result:=false;
          exit;
         end;   

      Stream.Read(VR^.SL, SizeOf(VR^.SL));  // Variable Length
     
     if delbit=1
       then
         begin
         if (Stream.size-Stream.position)<VR^.SL
         then
         begin
          dispose(VR);
          setlength(str,0);
          Stream.size:=pos;
          result:=false;
          exit;
         end;   
         SetLength(VR^.S, VR^.SL);             // Get memory to the variable
         Stream.Read(Pointer(VR^.S)^, VR^.SL); // Variable
         hash1.add(str,pointer(vr));
         end
      else
       begin
         Stream.position:=Stream.position+VR^.SL;
        setLength(str, 0);             
        dispose(VR);
       
       end;
     End;
  Except
   setlength(str,0);
    VR^.s:='';
    dispose(VR);
    result:=false;
    //Stream.size:=pos;   
    Clear;
  End;
End;
==

As you will notice this LoadFromStream() method brings Fault toleracy to ParallelVarFiler , so it's fault tolerant to power failure etc. and i think that the zipfile component must use something like that, cause Fault tolerancy is very important.


Thank you,
Amine Moulay Ramdane.
















aminer

  • Hero Member
  • *****
  • Posts: 956
Re: About the following Object pascal component...
« Reply #2 on: February 09, 2013, 09:56:40 pm »

Hello,

Question:

And how this zipfile component can be fault tolerant ?

Answer:

Every time you add a file to the zipfile , your must for  example use the same method that is using my ParallelVarFiler and verify for example the last file copied to see if it was copied correctly, and if the last
file was corrupted you will delete the last file, you must not scan all
the files like is doing ParallelVarFiler, just the last file copied to the zip file. And this is how you can bring fault tolerancy to your
zip archiver.



Thank you,
Amine Moulay Ramdane/
 










aminer

  • Hero Member
  • *****
  • Posts: 956
Re: About the following Object pascal component...
« Reply #3 on: February 09, 2013, 10:03:31 pm »

Hello,

If i have sometime i will implement an archiver that uses
my parallel compression library and  that will be fault tolerant also and that will support files larger than 4Gb . It will be better than the zipfile component.


That's my next project in my list.


Thank you,
Amine Moulay Ramdane.


 

TinyPortal © 2005-2018