ssCore.BinaryFile.readBytes

Read a block of bytes from the file.


Availability:

First available in version 3.7 build 197.


Input Parameters:

size - Number of bytes to read,

format - Desired data format. Valid values include: hex,byte,utf8.


Output Parameters:

result - The requested bytes in the requested format.

bytesRead - Number of bytes actually read from the file.

systemError - A system specific error code from the GetLastError function.


Asynchronous Mode:

When this method is called asynchronously, a return object containing the output parameters is passed to the specified callback function.

ssCore.BinaryFile.readBytes( paramsObject [, callbackParamsObject] [, errorParamsObject] );


Synchronous Mode:

When this method is called synchronously, a return object containing the output parameters is returned to the caller immediately.

var returnObject = ssCore.BinaryFile.readBytes( paramsObject );


Notes:

When a file is first opened or created the file pointer is set to 0 (the beginning of the file). Each call to readBytes advances the file pointer by the amount of data read.

Setting the format parameter to byte causes exactly one byte to be read from the file and returned as a value from 0 to 255. The size parameter should be set to 1 (the plugin will ignore larger values).

Setting the format parameter to utf8 reads exactly size bytes of data from the file and converts it to UTF8 format before returning it to Flash. This provides a convenient way to read text data without the overhead of using the hex strings required for pure binary data.

Setting the format parameter to hex reads exactly size bytes of data from the file and converts it to a hex string before returning it to Flash. Once you have the hex string you can use StringUtils.hexStringToArray (AS2) or StringUtils.hexStringToByteArray (AS3) to convert the data to a native Flash format that you can conveniently manipulate.

                

Examples:

Read the contents of a file one byte at a time and display the result.

var s:String = "";

ssCore.BinaryFile.open({path:"startdir://file.dat", accessMode:"read"});

do {

    var r:Object = ssCore.BinaryFile.readBytes({size:1, format:"byte"});

         if (r.bytesRead == 1)
        s += String.fromCharCode(Number(r.result));

         } while (Number(r.bytesRead) == 1);

ssCore.BinaryFile.close({});

ssDebug.trace(s);

Read the contents of a file as a UTF8 string. This is fine for reading text files, but if you are reading a binary file with zero's in it, they will terminate the string in Flash.

ssCore.BinaryFile.open({path:"startdir://file.dat", accessMode:"read"});

var r:Object = ssCore.BinaryFile.getSize({});
var fileSize:Number = Number(r.result);

r = ssCore.BinaryFile.readBytes({size:fileSize, format:"utf8"});
ssDebug.trace(r.result);

ssCore.BinaryFile.close({});

Read the contents of a file as a hex string. The hex string can contain any character, including zero's. Once you have the hex string you can use StringUtils.hexStringToArray (AS2) or StringUtils.hexStringToByteArray (AS3) to convert the data to a format you can manipulate easily in Flash.

ssCore.BinaryFile.open({path:"startdir://file.dat", accessMode:"read"});

var r:Object = ssCore.BinaryFile.getSize({});
var fileSize:Number = Number(r.result);

r = ssCore.BinaryFile.readBytes({size:fileSize, format:"utf8"});
ssDebug.trace(r.result);

ssCore.BinaryFile.close({});