JavaScriptでバイナリファイルの中身にアクセスできた

参考資料(というか主要なアイデアほとんど全部)はこちら。
http://mgran.blogspot.com/2006/08/downloading-binary-streams-with.html
何に使うのかはこれから考える。
でかいファイルを食わせてループでString.fromCharCodeを回したらFirefoxが死んでしまったのでそこだけ注意。
(mal_blueさん,nanto_viさんに直して頂いたコード版)

<html><head>
<script>
load_url = function(url) {
    var req = new XMLHttpRequest();
    req.open('GET',url,false);
    //XHR binary charset opt by Marcus Granado 2006 [http://mgran.blogspot.com]
    req.overrideMimeType('text/plain; charset=x-user-defined');
    req.send(null);
    if (req.status != 200) return '';
    return req.responseText;
}

write_binary_file = function(url) {
    // 49 => "1" (decimal)
  var filestream = load_url(url);
  var bytes = [];
  for (i = 0; i < filestream.length; i++)
    bytes[i] = filestream.charCodeAt(i) & 0xff;
  document.write(String.fromCharCode.apply(String, bytes));
}

</script></head><body>
<script>
  write_binary_file('読みたいファイルのURLをここに書く。')
</script>

</body></html>


追記:参考資料として用いたURLによると

If you use the code above, please leave the comment about the author (me) for recognition of the many hours of labor to find this out. Please bear in mind that even though it worked for me and I'm making this code available in the hope it may help you too, I do not take any responsibility for any problems this code may cause to you or your project!


とのことですので、ご利用になる方はご注意ください。