#142 Stream storing/extraction not working

Reported
closed-invalid
nobody
Archiving (51)
5
2011-09-23
2011-09-23
No

I am using the two below functions to save TMemoryStream streams into a ZIP file. In the prior versions, and including the 4.03 I ported myself several months ago, these worked, but with the latest they choke, mostly on extraction. I did have one weird error that I only got once on storing talking about specifying a span number.

My guess is it's Unicode related within the engine but not sure. Any ideas? Thanks.

procedure StoreToTar (InFilename : string; Files : string; Stream : TStream);
var
ZipKit : TAbZipKit;
begin
ZipKit := TAbZipKit.Create (MainForm);
with ZipKit do begin
ArchiveType := atZip;
ForceType := TRUE;

OpenArchive (InFilename);

DeleteFiles (Files); // delete the original file
AddFromStream (Files, Stream);

CloseArchive;
end; { with }
ZipKit.Free;
end; { StoreToTar }

procedure ExtractFromTar (InFilename : string; Files : string; var Stream : TStream);
var
ZipKit : TAbZipKit;
begin
ZipKit := TAbZipKit.Create (MainForm);
with ZipKit do begin
ArchiveType := atZip;
ForceType := TRUE;

Filename := InFilename;

ExtractToStream (JustFilenameS(Files), Stream);
Stream.Position := 0;

CloseArchive;
end; { with }
ZipKit.Free;
end; { ExtractFromTar }

Discussion

  • Zoë Peterson

    Zoë Peterson - 2011-09-23

    The problem is that you're using "with". TAbCustomZipBrowser, and it's descendants like TAbZipKit, now have a "Stream" property so you can load the archive from a stream rather than a file. That clashes with the Stream parameter you're passing into StoreToTar and ExtractFromTar, which means you're actually trying to add from or extract to the original zip archive's file stream. Change your parameter name to "outStream" and it'll start working.

     
  • Zoë Peterson

    Zoë Peterson - 2011-09-23
    • status: open --> closed-invalid
     
  • John Clements

    John Clements - 2011-09-23

    I replaced my function of:

    procedure ExtractFromTar (InFilename : string; Files : string; var Stream : TStream);

    with:

    procedure ExtractFromTar (InFilename : string; Files : string; var outStream : TStream);

    and by itself it didn't fix anything. I must be missing something else.

     
  • Zoë Peterson

    Zoë Peterson - 2011-09-23

    You need to change it on the lines where you're calling AddFromStream and ExtractToStream too.

     
  • John Clements

    John Clements - 2011-09-23

    I made the changes as I believe you suggested, and I don't get any errors savings, but on loading I get an error saying "Invalid file - not a PKZip file".

    Just fyi, I use ForceType as I am using a not .ZIP extension, our extension is proprietary to our application so is non-standard.

    I'm sorry for being so dense and/or causing issues.

    procedure StoreToTar (InFilename : string; Files : string; outStream : TStream);
    var
    ZipKit : TAbZipKit;
    begin
    ZipKit := TAbZipKit.Create (MainForm);
    with ZipKit do begin
    ArchiveType := atZip;
    ForceType := TRUE;

    OpenArchive (InFilename);

    DeleteFiles (Files);
    AddFromStream (Files, outStream);

    CloseArchive;
    end; { with }
    ZipKit.Free;
    end; { StoreToTar }

    procedure ExtractFromTar (InFilename : string; Files : string; var outStream : TStream);
    var
    ZipKit : TAbZipKit;
    begin
    ZipKit := TAbZipKit.Create (MainForm);
    with ZipKit do begin
    ArchiveType := atZip;
    ForceType := TRUE;

    Filename := InFilename;

    ExtractToStream (JustFilenameS(Files), outStream);
    outStream.Position := 0;

    CloseArchive;
    end; { with }
    ZipKit.Free;
    end; { ExtractFromTar }

     
  • Zoë Peterson

    Zoë Peterson - 2011-09-23

    The only cases where you'll see that error are when you try to load a file and it either isn't actually a zip or is corrupt. There doesn't appear to be anything wrong with the code you're posting. If you can share one of the files that's causing problems attach it to the bug report or email it to capeterson at users.sourceforge.net and I'll take a look.

     
  • John Clements

    John Clements - 2011-09-23

    I have submitted further source and the example file via email.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks