This content has been marked as final. Show 2 replies
You probably read fmsInstallerStream.bytesAvailable to a variable.
Finally got it working!
Thanks tzeng, it was mainly the issue of not reading bytesAvailable property to a variable. However, I will explain this problem to other users if they would encounter the same problem:
the reason I got EXACLY half of the code coppied is that:
bytesAbailable property of FileStream object returns the number of bytest from the CURRENT POSITION set by fmsInstallerStream.position to the end of file and NOT always from the begning of a file to its end. That's why when fmsInstallerStream.position was increased on each step of the loop, the loop updated the fmsInstallerStream.bytesAvailable property starting counting from the new (increased by 1) position. So with each step it was retrieving a decreased maximum i value and thus was stopping the loop just in the middle of the file (because i and so the fmsInstallerStream.position were exacly equal or higher than fmsInstallerStream.bytesAvailable property).
Additionally there was a mistake in the maximum i value anyway. The loop should stop at the value of fmsInstallerStream.bytesAvailable-1, so the if we use a "sharp" (<) comparison, there should be ... ; i < fmsInstallerStream.bytesAvailable; ...
Hope it shed some light on the issue. To clarify the problem even more, i attach the final code here:
var fmsInstallerFile:File = File.applicationDirectory.resolvePath("bin\\sth.exe");
var fmsInstallerStream:FileStream = new FileStream();
fmsInstallerStream.position = 0;
var file:File = File.desktopDirectory.resolvePath("coppied.exe");
var stream:FileStream = new FileStream();
var totalBytes = fmsInstallerStream.bytesAvailable;
for(var i:int = 0; i < totalBytes; i ++)
fmsInstallerStream.position = i;
tempByte = fmsInstallerStream.readByte();