// Here we create a character set that is necessary for // writing bytes accurately in binary mode. // CHARSET = []; for (i = 0; i < 256; i++) CHARSET[i] = (i < 128 || i > 159) ? String.fromCharCode(i) : "\u20AC\x81\u201A\u0192\u201E\u2026\u2020\u2021\u02C6\u2030\u0160\u2039\u0152\x8D\u017D\x8F\x90\u2018\u2019\u201C\u201D\u2022\u2013\u2014\u02DC\u2122\u0161\u203A\u0153\x9D\u017E\u0178".charAt(i - 128); // Create list of hex numbers from 00 to FF // and write them to a file: HexList = []; for (i = 0; i < 256; i++) HexList[i] = (i < 16 ? "0" : "") + i.toString(16); CreateHexFile("ASCIIJS.BIN", HexList); //////////////////////////////////////////////////////////////////// // This function creates a new binary file and writes bytes into it. // The function expects a string argument or a list of strings // containing hexadecimal numbers. The function converts each // hexadecimal digit pair into a byte and writes the bytes // to a file. Non-hexadecimal digits in the arguments are ignored. // // If the file already exists, it will be deleted and replaced // with the new content. The function returns 1 on success or // zero if something went wrong. // // This function can have one or more arguments. // The first argument must be the file name, followed by a string // or list or several string arguments or lists. // // Usage: INTEGER = CreateHexFile(FILENAME, [STRING OR LIST]) // function CreateHexFile(FileName, Content) { Content = (typeof(Content) == "object") ? Content.join("") : Content + ""; Content = Content.replace(/[^a-fA-F0-9]+/g, ""); if (Content.length & 1) Content += "0"; Content = Content.replace(/[a-fA-F0-9]{2}/g, function (n) { return CHARSET[parseInt(n, 16)]; }); try { var FSO = new ActiveXObject("Scripting.FileSystemObject"); F = FSO.CreateTextFile(FileName, 1, 0); F.Write(Content); F.Close(); return 1; } catch (e) {} return 0; }