Forum > Packages and Libraries

[SOLVED] LibTar - exception reading archived file to TStream

(1/1)

Vodnik:
Hello,

Attached is a simplified project using LibTar package, delivered with Lazarus.
It opens TAR archive, list archived files and tries to read archived file content to TStream for further processing. The last operation causes EStreamError exception with message "Writing to TStream is not supported".

Problem occur when using
PROCEDURE TTarArchive.ReadFile (Stream : TStream);
while using
PROCEDURE TTarArchive.ReadFile (Filename : STRING);
successfully extract archived files.

LibTar package seems to be imported from Delphi, original source code at www.destructor.de

I'm using Lazarus V 2.2.4, 64-bit, Windows 10.

Vodnik:
That was my fault.
TStream is abstract class and shouldn't be used here.
Using TStringStream instead solves the problem.

Vodnik:
Well, this was not end of a story...

There is an issue when processing some TARs (supposingly created under Linux) in Windows.
Procedure FindNext causes exception when reading buffer to FStream (see LibTar.pp, line 598):


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  // --- Scan until next pointer  IF FBytesToGo > 0 THEN    FStream.Seek (Records (FBytesToGo) * RECORDSIZE, soCurrent);   // --- EOF reached?  Result := FALSE;  CurFilePos := FStream.Position;  TRY    FStream.ReadBuffer (Rec, RECORDSIZE);    if Rec [0] = #0 THEN EXIT;   // EOF reached  EXCEPT    EXIT;   // EOF reached, too    END;  Result := TRUE; 
Adding trivial exception processing solves the problem:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  EXCEPT    on E: Exception do      EXIT;   // EOF reached, too  END; 

MarkMLl:
Is this LibTar being used directly, or with a fancy class wrapper? I'd hardly call myself the local expert but have previously commented on the otiosity of some of this stuff https://forum.lazarus.freepascal.org/index.php/topic,59296.msg442107.html#msg442107

I think that I'd note however that most if not all Linux systems will be running GNU Tar these days, which is pretty much the standard bearer as far as the format is concerned. I've worked with Sun systems in the past that used a different implementation, but would be surprised if you came across that.

There have, over the years, been minor format changes, including adding user and group names to file specifications rather than simply assuming that every unix system will have the same uid/gid numbers. However I think that things have been fairly stable for the last ten years or so, so again I'd be surprised if you were bitten by that.

A more serious possibility would be is the file had been created using a compression library which hadn't been linked into the tar implementation that you're running... which is a distinct possibility if you're not using a prebuilt port to Windows of GNU Tar.

MarkMLl

Navigation

[0] Message Index

Go to full version