On 07.02.2012 17:12, Reinier Olislagers wrote:
I have the following code, adapted from pasbzip.pas (bzip2 example)
uses ...bzip2..
const
BufferSize = 4096;
var
infile, outfile: Tbufstream;
decoder: Tbzip2_decode_stream;
a: array[1..BufferSize] of byte;
readsize: cardinal;
Status: boolean;
begin
Status := False;
result:=false;
...
try
infile.init(SourceFile, stopenread, 4096);
outfile.init(TargetFile, stcreate, 4096);
decoder.init(@infile);
if decoder.status<> stok then
begin
...
repeat
readsize := BufferSize;
decoder.Read(a, readsize);
Dec(readsize, decoder.short);
outfile.Write(a, readsize);
until decoder.status<> 0;
end;
infile.done;
outfile.done;
...
Code bombs at decoder.Read(a, readsize). readsize=0 according to debugger.
readsize=cardinal; according to help "an unsigned 32-bit integer".
However,
http://wiki.lazarus.freepascal.org/Multiplatform_Programming_Guide#32.2F64_bit
seems to imply Cardinal can vary between 32 bit and 64 bit.
Is that the culprit or am I doing anyth else wrong?
Does your stream contain at least 4096 bytes? According to the
documentation here
http://www.freepascal.org/docs-html/rtl/objects/tstream.read.html the
Read procedure does not perform any check.
Important note in case you're not aware of it: Tbzip2_decode_stream is
NOT a descendant of Classes.TStream, but of Objects.TStream, thus you
should look at the documentation of unit Objects (you can reach it from
the above mentioned link).
Also "Cardinal" is always 32-Bit wide. The only types that change
depending on bitness are "Pointer", "PtrUInt" and "PtrInt".
Regards,
Sven
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal