Forum > General

SOLVED Pack Files into one and extract

<< < (2/2)

wp:
I guess the issue is in the y loop of Button2Click (Extract): You provide a buffer with 10240 bytes, and if the file is larger you want to read/write in parts, until all is done. you calculate the number of iterations needed as FileSize div 10240, but begin the loop with y=1. This is a problem when the file is smaller than 10240 bytes - now the loop is not executed at all (for y := 1 to 0). Keep in mind: working with 1-based loops has many disadvantages, better to use a 0-based loop:


--- 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";}};} ---    for y := 0 to fileheader.fSize div 10240-1 do    begin      blockread(BagFile, TBuffer, sizeof(TBuffer), bRead);      blockwrite(out_file, TBuffer, bRead, bWrote);    end;  
To get accustomed to the 0-based style I'd also propose to declare TBuffer as array[0..10240-1] (rather than array[1..10240]) - it absolutely is unimportant here, but in case of dynamic arrays you always have 0-based indices. For me personally it is the most annoying mental exercise to switch between 1-based and 0-based thinking.

I'd also recommend to call ForceDirectories(lzExtractTo) after assigning a value to lzExtractTo, in order to make sure that the destination directory exists (along with all intermediate folders).

DreamVB:
Thanks Roland57 that seems to work it packing and extracting now how I want it to, thanks to all the rest that helped me to.

I now made a small class and I thought I share it an case someone else needs something like this. also now extracts with full paths.

Navigation

[0] Message Index

[*] Previous page

Go to full version