ssCore.BinaryFile.writeBytes

Write a block of bytes to the file.


Availability:

First available in version 3.7 build 197.


Input Parameters:

data - Data to be written, the format of the data is specified by the 'format' parameter.

format - Identify the format of 'data' parameter. Valid values include: hex,byte,utf8.


Output Parameters:

bytesWritten - Number of bytes actually written to 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.writeBytes( 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.writeBytes( 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 writeBytes advances the file pointer by the amount of data written.

If you set the format parameter to byte then writeBytes expects a decimal value in the range 0..255 (inclusive) to be supplied in the data parameter and exactly one byte will be written to the file at the current file pointer.

If you set the format parameter to utf8 then writeBytes will interpret the string passed in the data parameter as a UTF8 string and write it to the flie at the current file pointer. You don't have to tell it how many bytes to write, that will be determined automatically.

If you set the format parameter to hex then writeBytes will interpret the string passed in the data parameter as a hex string and convert it to a buffer full of bytes and write it to the flie at the current file pointer. You don't have to tell it how many bytes to write, that will be determined automatically.

                

Examples:

Demonstrates the various methods of writing data from Flash to a binary file.

ssCore.BinaryFile.create({path:"startdir://file.dat", accessMode:"write", failIfExists:"false"});

ssCore.BinaryFile.writeBytes({data:65, format:"byte"}); // A
ssCore.BinaryFile.writeBytes({data:66, format:"byte"}); // B
ssCore.BinaryFile.writeBytes({data:67, format:"byte"}); // C
ssCore.BinaryFile.writeBytes({data:13, format:"byte"}); // \r
ssCore.BinaryFile.writeBytes({data:10, format:"byte"}); // \n

ssCore.BinaryFile.writeBytes({data:"i am the utf8 string\r\n", format:"utf8"});

ssCore.BinaryFile.writeBytes({data:"6162630D0A", format:"hex"}); // abc\r\n

ssCore.BinaryFile.close({});