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?

2
  • 1
    What value does data have when the error is thrown? What's the error? Commented Nov 10, 2010 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. Commented Nov 10, 2010 at 19:51

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.