5

I am developing a function in Javascript using FileSystemObject, where I just have to write in a file the binary data we are provided. This is my function.

function exportFile(data)
{   
    var fso, f2;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    f2=fso.CreateTextFile("C:\\example.js",true);
    f2.Write(data);
    f2.Close();
}

Nevertheless it doesn't always work (error on f2.Write(data)). I guess it is because one or both reasons: - Write function does not accept binary data (ASCII from 0-255) - There is a maximum size for "data" in f2.Write(data)

Could you help me, please?

UPDATE:

I get this error (translated): Message: Argument or call to function not valid Which technology should I use, then, if Javascript doesn't work with plain block 8 bit values?

MrSmith42
  • 9,961
  • 6
  • 38
  • 49
  • 1
    What value does `data` have when the error is thrown? What's the error? – Matt Ball Nov 10 '10 at 19:50
  • What is the error you get? I suspect this is going to be quite difficult from Javascript because Javascript really has no appropriate data type for holding a block of plain 8-bit values. Javascript strings are 16-bit Unicode characters. – Pointy Nov 10 '10 at 19:51

1 Answers1

3

FileSystemObject is notably limited, even for writing UTF-8 files satisfactorily I have had to resort to another solution: ADODB.Stream

http://www.w3schools.com/ADO/ado_ref_stream.asp

Benjol
  • 63,995
  • 54
  • 186
  • 268