Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming.threads > #1356

Re: About the zipfile component...

From aminer <aminer@toto.ca>
Newsgroups comp.programming.threads
Subject Re: About the zipfile component...
Date 2013-02-09 15:37 -0800
Organization A noiseless patient Spider
Message-ID <kf6bv8$r5l$10@dont-email.me> (permalink)
References <kf6btj$r5l$7@dont-email.me>

Show all headers | View raw


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 component to be fault tolerant..


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.


Back to comp.programming.threads | Previous | NextPrevious in thread | Find similar


Thread

About the zipfile component... aminer <aminer@toto.ca> - 2013-02-09 15:36 -0800
  Re: About the zipfile component... aminer <aminer@toto.ca> - 2013-02-09 15:37 -0800

csiph-web