on writeBinaryFile filePath, byteList, fileStartByte, listStartByte, deleteOriginalFile
result = 0
fileObj = new (xtra "fileIO")
if deleteOriginalFile then
-- It's often "cleaner" to remove the existing file
-- though you obviously wouldn't do this when editing
-- an MP3 file
fileObj.openFile (filePath, 0)
fileObj.delete ()
fileObj.createFile (filePath)
end if
fileObj.openFile (filePath, 2)
-- Attempt to open the file with write-only access
if fileObj.status () = 0 then
listLength = byteList.count
if fileStartByte.voidP then fileStartByte = 1
-- Set default positions if none were supplied via
-- the fileStartByte & listStartByte parameters
if listStartByte.voidP then listStartByte = 1
fileObj.setPosition (fileStartByte-1)
-- Set the write position in the file & begin dumping
-- the list contents into the file
repeat with index = listStartByte to listLength
fileObj.writeChar (numToChar (byteList[index]))
end repeat
result = 1
end if
fileObj.closeFile ()
fileObj = 0
return result
end