convering a javascript file to byte[] array?

i would like to expand my muliplayer game with the ability for the host to send custom javascripts to clients. These scripts would be written to client asset folders and added to objects.

i have had much success with this same process sending image files and text files. I am hoping it is possible to send script files in a similar manner. I am looking for any helpfull advise or whether this is even possible before i spend nights typing away just to find myself banging my head against the keyboard finding out this is not possible. haha.

i would assume the process would maybe look something like this…

import System.IO;
var blahbytes:byte[];
var adp:String;
adp=Application.dataPath+"/custom scripts/";
var myobject:GameObject;

if(File.Exists("adp+"blahblah.js")){ 
blahbytes = File.ReadAllBytes("blahblah.js");
networkView.RPC ("getcode", RPCMode.All,blahbytes);


@RPC
function getcode(cd : byte[]){
File.WriteAllBytes(adp+"blahblah.js, cd);
// how do i look up a component manually from the folder on runtime ?
myobject.AddComponent ("blahblah");
}

would something like this work?

No, that won’t work. In order to add a script as a component, it has to already exist as compiled code in the project, so that’s not possible to do in a build. You can, however, use the eval() function with text and have that be compiled on the fly, however that doesn’t work on all platforms. Plus it’s a questionable hole to leave open since being able to run arbitrary code written by anyone is pretty clearly open to abuse.